react-editext
react-editext copied to clipboard
Value is not controllable (uncontrolled) by prop `value`
Describe the bug
The component has its own internal state of value and doesn't obey the external prop value
Expected behavior
value should be fully controlled by the external prop value
CodeSandbox URL https://codesandbox.io/s/dazzling-jones-l4esq In this sandbox, users should not be able to change the value of the editext.
Version: 4.2.1
Work-around for anyone who needs it. DISCLAIMER: This is anti-pattern as it make React fail to memorize the component, so React has to unmount and mount the component again and again.
const [version, setVersion] = useState('0');
const updateVersion = useCallback(() => {
setVersion(String(Math.random()));
}, []);
const onSave = useCallback((v) => {
updateVersion();
}, []);
const onCancel = useCallback((v) => {
updateVersion();
}, []);
return (
<Wrapper>
<EdiText
key={version} // keeps React re-mount the component at every renders
type="text"
value={value} // controlled ny external prop
onSave={onSave}
onCancel={onCancel}
/>
</Wrapper>
);
Hi, thanks for pointing this out! Yes, when the value is set by the external prop it shouldn't be changed via the user action. I will look into that deeply. Meanwhile, I am open to Pull Requests if you have any recommendations.
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This is still relevant. Unfortunately, I don't have time to look into the package :(
Please help me to find the way here:
- If the
valueprop is passed, we shouldn't change it anyway, right? - This is for
view modeI believe. What happens if the user clicks to edit button to enableeditingmode? - What will happen if the user changes the text in
editing modethen press to save button when there is a controlledvalue?
Thanks
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Sorry @Salioguzhan, I didn't have time to reply you sooner. Thank you so much for the time & efforts.
Basically, as a FE dev, I expect react-editext to have similar behaviors to <input />
- If the value prop is passed, we shouldn't change it anyway, right?
- Yes. I think so
- This is for view mode I believe. What happens if the user clicks to edit button to enable editing mode?
- I think this will be helpful in both modes
- What will happen if the user changes the text in editing mode then press to save button when there is a controlled value?
- I think the component will fire an
onChangeevent. And devs need to handle that event to update his state tp keep the component to update correctly
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Yes. I will look into it again based on the feedback from @Nogias9x
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
I am closing this as won't fix. i don't have time to fix this for now. I am open to pull requests.