Skip to content
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

useUnmountEffect - callback is not updated when it changes #756

Closed
andbjer opened this issue May 12, 2022 · 1 comment · Fixed by #758
Closed

useUnmountEffect - callback is not updated when it changes #756

andbjer opened this issue May 12, 2022 · 1 comment · Fixed by #758
Assignees
Labels
🕯️ bug fix One or more bugs fixed released

Comments

@andbjer
Copy link

andbjer commented May 12, 2022

Prior Issues

No prior issues

What is the current behavior?

The callback passed to useUnmountEffect is not updated when it changes.

Steps to Reproduce

Consider this component. On unmount, onSave is never called even if you've changed the value. Reproduction available here

interface IProps {
  initialValue: string;
  onSave: (value: string) => void;
}
export const Input = ({ initialValue, onSave }: IProps) => {
  const [value, setValue] = useState(initialValue);

  const handleSave = useCallback(() => {
    if (value !== initialValue) {
      onSave(value);
    }
  }, [value, initialValue, onSave]);

  useUnmountEffect(() => {
    handleSave();
  });

  return <input value={value} onChange={(e) => setValue(e.target.value)} />;
};

What is the expected behavior?

The callback passed to useUnmountEffect should be updated whenever the callback changes.

Environment Details

  • @react-hookz/web version: 13.2.1
  • react version: 17.0.2
  • react-dom version: 17.0.2
  • typescript version: 4.6.3
  • OS: macOS Monterey (12.3.1)
  • Browser: Google Chrome Version 101.0.4951.64
  • Did this work in previous versions? No
@xobotyi xobotyi added the 🕯️ bug fix One or more bugs fixed label May 12, 2022
@xobotyi xobotyi self-assigned this May 12, 2022
@andbjer andbjer changed the title useUnmountEffect - callback is not update when it changes useUnmountEffect - callback is not updated when it changes May 12, 2022
github-actions bot pushed a commit that referenced this issue May 12, 2022
## [14.2.1](v14.2.0...v14.2.1) (2022-05-12)

### Bug Fixes

* `useUnmountEffect` now invokes changing effect functions ([#758](#758)) ([380637a](380637a)), closes [#756](#756)
@xobotyi
Copy link
Contributor

xobotyi commented May 12, 2022

🎉 This issue has been resolved in version 14.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕯️ bug fix One or more bugs fixed released
Development

Successfully merging a pull request may close this issue.

2 participants