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

Persist showRaw and hiddenLabel Checkbox example #10

Closed
lucasferreiralimax opened this issue Oct 28, 2024 · 0 comments · Fixed by #11
Closed

Persist showRaw and hiddenLabel Checkbox example #10

lucasferreiralimax opened this issue Oct 28, 2024 · 0 comments · Fixed by #11
Assignees
Labels
enhancement New feature or request hacktoberfest

Comments

@lucasferreiralimax
Copy link
Member

Implement local storage persistence for the showRaw and hiddenLabel checkbox states to allow users to retain these preferences across page reloads. This enhancement will save the selected states, ensuring a more consistent user experience.

Requirements

  1. Initialize State from localStorage:

    • Load initial values for the showRaw and hiddenLabel checkboxes from localStorage.
    • If no value exists in localStorage, default to false for both states.
  2. Update localStorage on State Change:

    • Whenever the showRaw or hiddenLabel checkbox is toggled, update the value in localStorage to persist the setting.
  3. Acceptance Criteria:

    • The showRaw and hiddenLabel states should persist after page reload.
    • If the user clears localStorage, the checkboxes should reset to their default values (false).

Technical Implementation

  1. State Initialization:

    • Use localStorage.getItem to initialize showRaw and hiddenLabel as booleans.
  2. State Persistence:

    • Use React’s useEffect to monitor changes to each checkbox state and update localStorage when changes occur.
Screenshot 2024-10-28 at 02 57 29 Screenshot 2024-10-28 at 02 57 34
@lucasferreiralimax lucasferreiralimax self-assigned this Oct 28, 2024
@lucasferreiralimax lucasferreiralimax linked a pull request Oct 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant