-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathMap.js
More file actions
25 lines (23 loc) · 708 Bytes
/
Map.js
File metadata and controls
25 lines (23 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import * as React from 'react'
import Value from './Value'
import renderProps from '../utils/renderProps'
const Map = ({ initial = {}, onChange, ...props }) => (
<Value initial={{ ...initial }} onChange={onChange}>
{({ value: values, set, reset }) =>
renderProps(props, {
values,
clear: () => set({}),
reset,
set: (key, updater) =>
set(prev => ({
...prev,
[key]: typeof updater === 'function' ? updater(prev[key]) : updater,
})),
get: key => values[key],
has: key => values[key] != null,
delete: key => set(({ [key]: deleted, ...prev }) => prev),
})
}
</Value>
)
export default Map