Development of useTheme Hook for Theme Management #14
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
CosmicCoder-sudo/react-hook-kit#14
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description:
The objective of this issue is to implement a useTheme custom hook in our codebase, providing a reusable and efficient method for managing different application themes.
Details:
Currently, we lack a dynamic, application-wide solution for managing themes. A useTheme hook will centralize theme management, enhancing code reusability and facilitating theme changes based on user preference or system settings.
The expected behavior of this hook is:
Provide an API to get the current theme.
Allow changing the current theme.
Persist the theme selection across sessions (optional, based on requirements).
Tasks:
Develop the useTheme hook according to the specifications.
Write unit tests to ensure the hook functions as expected.
Document the hook's functionality, usage, and provide examples.
Ensure the hook integrates well with existing theming solutions and does not cause unnecessary re-renders.
Acceptance Criteria:
The hook correctly fetches and sets the current theme.
The hook's theme changes are reflected application-wide.
The hook is backed by comprehensive unit tests which pass.
The hook is properly documented.
The hook does not negatively impact app performance.
Some questions to solidify resulting hook:
What's difference between useTheme and useLocalStorage? Is theme value a boolean, simple string, union of strings, enum,
object, something else?
Does fetch imply kind of storage (session, local, other), remote provider, variable in a closure, something else?
Is theme related to system theme (dark, light) or arbitrarily defined one (solaris, dark, default)?
@Askadar
Sure, let's go through these questions one by one:
What's the difference between useTheme and useLocalStorage?
useTheme would be a hook specifically designed to handle the theme setting in your application. It might internally use a method like useLocalStorage to persist the user's theme preference across sessions, but its main purpose is to provide an interface to get and set the current theme. The implementation of useTheme might involve triggering rerenders when the theme changes, providing default values, and integrating with the rest of your theming system.
useLocalStorage, on the other hand, would be a more general hook that provides an interface to the localStorage web API. It could be used to store any type of data between user sessions, not just the theme.
Is the theme value a boolean, simple string, union of strings, enum, object, something else?
This entirely depends on your application's requirements. In a simple use case, the theme might be a boolean representing whether the user prefers a dark or light theme. In a more complex application, it might be a string or enum representing one of many possible themes. If you want to allow users to customize their themes, the theme could even be an object storing color values for different parts of your UI.
Does fetch imply kind of storage (session, local, other), remote provider, variable in a closure, something else?
The term "fetch" typically refers to making a network request, often to a remote API. However, in the context of a useFetch or useAsync hook, "fetch" could be a more general term for any asynchronous operation, which could include getting data from localStorage, sessionStorage, or a variable in a closure, depending on your specific needs and implementation.
Is theme related to system theme (dark, light) or arbitrarily defined one (solaris, dark, default)?
Again, this depends on your application's requirements. You could have a useTheme hook that respects the user's system theme settings, changes based on time of day, or allows the user to select from a list of predefined themes. The design of the useTheme hook should be guided by the needs of your users and the overall goals of your application.
I hope these answers help! If you have any further questions, please don't hesitate to ask.