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
Provide React Hooks #4317
Comments
Has this been answered somewhere? |
This doesn't seems getting any attention at all in this library. But Hooks could be the dream for this because it will remove all the boilerplate and complexity regarding setup the form just to work. |
React-Redux v7.1 (currently in alpha) offers hook alternatives to Is there any interest for this feature in the core team? |
I think there's no reason to use And this: https://github.com/final-form/react-final-form And |
(redacted, I thought I was commenting on another repo) |
You can hack it in yourself at least: /**
* @flow
*/
import { useContext } from 'react'
import { ReduxFormContext } from 'redux-form/es/ReduxFormContext'
import { type Context } from 'redux-form/es/types'
export default function useReduxForm(): Context {
return useContext(ReduxFormContext)
} /**
* @flow
*/
import useReduxForm from './useReduxForm'
import { useSelector } from 'react-redux'
import getFormValues from 'redux-form/es/getFormValues'
export default function useFormValue(name: string): any {
const { form } = useReduxForm()
return useSelector(state => getFormValues(form)(state)?.[name])
} |
Providing react hooks, we will need to bump react version to 16.8 (even better 16.9), and this is a breaking change from the library point of view. But as we know react is back compatible and users of |
@jerrygreen sure, let me rewrite a hundred forms to another library just to have a hook ;) |
@pokonski adding hooks should not affect curent components behaviour. |
@iamandrewluca you could avoid the breaking change in required React version if existing components don't use hooks under the hood and users have to import the hooks directly from a specific submodule/subfolder like |
@jedwards1211 yes this is possible, but then we will have to maintain 2 codebases, one with hooks, and one without.
So I think we can increase React minor version with ease because of semver. |
I think the people who came up with semver would be very angry about that idea. Responsibly maintained packages always use a new major version to drop support for old versions of dependencies or node. If you publish a minor update any developers who happen to have something like "react": "16.7.0",
"redux-form": "^8.0.0", will get a nasty unexpected surprise. Please don't contribute to developer suffering. Just do the right thing and release it as a major version bump. |
Example of responsible semver usage:
|
@jedwards1211 I mentioned this case, and in this case I think that usign If he respects semver, it should be for most of libraries he is using, otherwise, all libraries should stay on hold, and bumping major version for every minor dependency upgrade.
ps: https://semver.org/#what-should-i-do-if-i-update-my-own-dependencies-without-changing-the-public-api |
@iamandrewluca that section addresses dependencies used internally, not peer dependencies. The bottom line of semver is, if any project would break if the new release is dropped in, it should be released as a new major version. |
Breaking changes
|
Breaking changes
|
"The major change for this release is that connect is now implemented using Hooks internally. Because of this, we now require a minimum React version of 16.8.4 or higher." |
@jedwards1211 ok, I got it 🙂 |
@iamandrewluca I meant in my reply that his advice to rewrite to a completely different form library is a reckless suggestion. That would be weeks of work for a small convience. |
At this moment I think no one is interested in allocating time for |
Can you provide full page example with a form? |
Has there been any thoughts on React Hooks adoption vs using a HOC? I know things are early and even Redux is still working to get a full grasp on how to do things in the React Hooks world (here, and here), but just thought I'd throw this out there for discussion and thoughts of what it might look like once Redux gets proper hook support.
The text was updated successfully, but these errors were encountered: