react-editext icon indicating copy to clipboard operation
react-editext copied to clipboard

Value is not controllable (uncontrolled) by prop `value`

Open terrynguyen255 opened this issue 4 years ago • 10 comments

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

terrynguyen255 avatar Nov 06 '21 19:11 terrynguyen255

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>
  );

terrynguyen255 avatar Nov 06 '21 20:11 terrynguyen255

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.

alioguzhan avatar Nov 07 '21 09:11 alioguzhan

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.

stale[bot] avatar Jan 03 '22 20:01 stale[bot]

This is still relevant. Unfortunately, I don't have time to look into the package :(

terrynguyen255 avatar Jan 04 '22 07:01 terrynguyen255

Please help me to find the way here:

  1. If the value prop is passed, we shouldn't change it anyway, right?
  2. This is for view mode I believe. What happens if the user clicks to edit button to enable editing mode?
  3. What will happen if the user changes the text in editing mode then press to save button when there is a controlled value?

Thanks

alioguzhan avatar Jan 04 '22 12:01 alioguzhan

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.

stale[bot] avatar Apr 16 '22 03:04 stale[bot]

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 />

  1. If the value prop is passed, we shouldn't change it anyway, right?
  • Yes. I think so
  1. 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
  1. 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 onChange event. And devs need to handle that event to update his state tp keep the component to update correctly

terrynguyen255 avatar Apr 21 '22 05:04 terrynguyen255

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.

stale[bot] avatar May 01 '22 06:05 stale[bot]

Yes. I will look into it again based on the feedback from @Nogias9x

alioguzhan avatar May 01 '22 20:05 alioguzhan

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.

stale[bot] avatar Jul 10 '22 18:07 stale[bot]

I am closing this as won't fix. i don't have time to fix this for now. I am open to pull requests.

alioguzhan avatar Mar 25 '23 11:03 alioguzhan