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

Feature Request: useOnLoadEffect() -> empty dependency array useEffect wrapper #28866

Open
laspencer91 opened this issue Apr 18, 2024 · 0 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@laspencer91
Copy link

laspencer91 commented Apr 18, 2024

Currently React requires an empty dependency array to use an effect only on components' initial render.

This frequently causes confusion for new React developers that could be remedied with the addition of a unique named hook that handles this case. Adheres to a design principle that says "Names should specify their intent, if a function or variable requires documentation then its name does not specify its intent".

// Requires the developer to know what this does either through prior trial and error, or prior learning.
// Often mistakenly interpreted by new developers as an effect that will run every render.
useEffect(() => {

}, [])

// Name provides the intent. Developer can interpret behavior without framework specific knowledge.
useOnLoadEffect(() => {

});

This could provide clarity for React applications. Upon implementation, could potentially provide hinting to use the new hook when an empty array is detected to remain backwards compatible. Same logic could be applied for useMemo.

useOnLoadMemo(() => {

});
@laspencer91 laspencer91 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 18, 2024
@laspencer91 laspencer91 changed the title Feature Request: useOnLoadEffect() -> empty dependency array useEffect wrapper. Feature Request: useOnLoadEffect() -> empty dependency array useEffect wrapper Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

1 participant