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

useSessionStorage Hook: initialization issue #4353

Closed
WouterCypers opened this issue May 8, 2023 · 1 comment · Fixed by #4355
Closed

useSessionStorage Hook: initialization issue #4353

WouterCypers opened this issue May 8, 2023 · 1 comment · Fixed by #4355
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@WouterCypers
Copy link

Describe the bug

When using the useSessionStorage hook and initialising the value to an empty string, React yields the folowwing error:

Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components

The hook seems to save the empty string as undefined instead of a literal ''.

Reproducer

No response

PrimeReact version

9.2.1

React version

18.x

Language

TypeScript

Build / Runtime

Next.js

Browser(s)

No response

Steps to reproduce the behavior

  1. Create a variable using useSessionStorage initialised to '':
  const [usernameInput, setUsernameInput] = useSessionStorage(
    '',
    'usernameInput'
  );
  1. Use it on an InputText element:
          <InputText
            value={usernameInput}
            onChange={(e) => setUsernameInput(e.target.value)}
          />
  1. Check console log.
    Screenshot 2023-05-08 at 13 25 46

Expected behavior

No error.

@WouterCypers WouterCypers added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label May 8, 2023
@melloware melloware changed the title Component: useSessionStorage hook useSessionStorage Hook: initialization issue May 8, 2023
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels May 8, 2023
@melloware melloware self-assigned this May 8, 2023
@melloware melloware added this to the 9.4.0 milestone May 8, 2023
melloware added a commit to melloware/primereact that referenced this issue May 8, 2023
@melloware
Copy link
Member

Thanks for the reproducer I was able to reproduce it and fix it. See PR.

melloware added a commit to melloware/primereact that referenced this issue May 8, 2023
melloware added a commit to melloware/primereact that referenced this issue May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants