-
-
Notifications
You must be signed in to change notification settings - Fork 25
Add value field to Provider for reusability. #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I agree! I like the idea |
Yes, I think callbacks should in Provider's props instead of const defaultStore = {
quantity: 2,
userName: 'Aral',
age: 31,
}
const { Provider, useQuantity } = createStore(defaultStore);
// Make own provider.
export const MyContextProvider = ({ store, children }) => {
const apolloClient = useApolloClient();
const callbacks = {
quantity: (newValue, prevValue, setValue) => {
// Update quantity on API
apolloClient.mutate(...)
// Revert state change if it fails
.catch(e => setValue(prevValue))
},
age: (newValue, prevValue, setValue) => {
if (newValue > 100) {
alert("Sorry, no more than 100 😜");
setValue(prevValue);
}
}
}
return (
<Provider store={store} callbacks={callbacks}>
{children}
</Provider>
);
}; |
Done on fragstore 0.4.0 (fragmented-store is renamed to fragstore) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of this package are you using?
0.2.1
What problem do you want to solve?
Default value of store is fixed so store's reusability is not good.
What do you think is the correct solution to this problem?
Add
value
option to Provider props. It will looks like original Context API'sProvider
.It makes breaking change (because value field of Provider is required field), so I want to know how do you think about it.
Are you willing to submit a pull request to implement this change?
After maintainer's feedback, yes.
Example
The text was updated successfully, but these errors were encountered: