4 ms·
Just a quick one: why would you need redux for forms? This is in my opinion a total overkill. I have forms either having their own state or (preferred) just us
by dafrie 7y ago
Just a quick one: why would you need redux for forms? This is in my opinion a total overkill.
I have forms either having their own state or (preferred) just use Formik for all of this. In my stack, this then allows to just add a field in the GraphQL schema (backend), add it in the query, add the formik field + yup validation and done.
- jypepin 7y agoSome people would argue that if using Redux, also having local state logic is an anti pattern. That would mean that if you use Redux, a form also requires actions for form update/submit/success/error and the form data should be stored in the redux store. That is one of the main issues I have with Redux, which I feel adds automatic complexity for simple things, but at the same time I'm not sure if it's very good to have a mix of tings happening from store/actions/reducers and others from local state/ajax.
- ryanbrunner 7y ago> Some people would argue that if using Redux, also having local state logic is an anti pattern. I won't disagree that this is a popular opinion, but there's little practical benefit to storing state that's truly local to a single component (or a very small tree) in Redux just because it's there. Even the maintainers of Redux maintain that it's perfectly acceptable to use local state - https://redux.js.org/faq/organizing-state#do-i-have-to-put-all-my-state-into-redux-should-i-ever-use-react-s-setstate https://redux.js.org/faq/organizing-state#do-i-have-to-put-a...
- scns 7y agoAbramov advises against using redux for forms
- fnky 7y agoI don't see how you can blame something for adding complexity based on what other people _think_ is an anti-pattern. In fact, it's most of the times not desired to update your store before you know the data has been validated anyway. The store should always be the source of truth, but that also means that it should be valid. That's the approach I am going with in any case when working with some kind of global state.
- yawaramin 7y agoOr use the browser's built-in form state management: https://medium.com/@everdimension/how-to-handle-forms-with-just-react-ac066c48bd4f https://medium.com/@everdimension/how-to-handle-forms-with-j... Bonus: it's almost certainly more accessible than custom solutions.