generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add shared store to context (#238)
- Loading branch information
1 parent
0520a0a
commit 87854ca
Showing
12 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {useDynamicFormsCtx} from './useDynamicFormsCtx'; | ||
|
||
export const useFormShared = <SharedStore extends Record<string, any>>() => | ||
useDynamicFormsCtx().shared as { | ||
store: SharedStore; | ||
onChangeShared: <Name extends keyof SharedStore, Value extends SharedStore[Name]>( | ||
name: Name, | ||
value: Value, | ||
) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
export const useFormSharedStore = () => { | ||
const [store, setStore] = React.useState({}); | ||
|
||
const onChangeShared = React.useCallback( | ||
(name: string, value: any) => setStore((s) => ({...s, [name]: value})), | ||
[setStore], | ||
); | ||
|
||
return {store, onChangeShared}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from './constants'; | ||
export * from './Controller'; | ||
export * from './DynamicField'; | ||
export {useMutateDFState, useStoreValue} from './hooks'; | ||
export {useMutateDFState, useStoreValue, useFormShared} from './hooks'; | ||
export * from './types'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {useDynamicFormsCtx} from './useDynamicFormsCtx'; | ||
|
||
export const useViewShared = <SharedStore extends Record<string, any>>() => | ||
useDynamicFormsCtx().shared as { | ||
store: SharedStore; | ||
onChangeShared: <Name extends keyof SharedStore, Value extends SharedStore[Name]>( | ||
name: Name, | ||
value: Value, | ||
) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
export const useViewSharedStore = () => { | ||
const [store, setStore] = React.useState({}); | ||
|
||
const onChangeShared = React.useCallback( | ||
(name: string, value: any) => setStore((s) => ({...s, [name]: value})), | ||
[setStore], | ||
); | ||
|
||
return {store, onChangeShared}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters