-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Slate docs say to use useMemo, should be useRef #3198
Comments
Seems like we can use https://github.com/alexreardon/use-memo-one and maybe expose it as a |
4 tasks
dmnd
added a commit
to dmnd/slate
that referenced
this issue
Jan 5, 2022
As already discussed almost a year ago in ianstormtaylor#3198, `useMemo` doesn't guarantee persistence. This breaks Fast Refresh. `useState` without a setter is a straightforward fix that avoids dependencies; let's get the docs updated so Fast Refresh works again. Fixes ianstormtaylor#3198
DougReeder
pushed a commit
to DougReeder/slate
that referenced
this issue
Apr 3, 2022
As already discussed almost a year ago in ianstormtaylor#3198, `useMemo` doesn't guarantee persistence. This breaks Fast Refresh. `useState` without a setter is a straightforward fix that avoids dependencies; let's get the docs updated so Fast Refresh works again. Fixes ianstormtaylor#3198
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to request a feature or report a bug?
Bug
What's the current behavior?
In the docs, it says to use useMemo for the editor instance passed to the
<Slate>
component so it is "stable across renders". useMemo does not guarantee identity between renders (https://reactjs.org/docs/hooks-reference.html#usememo) and talking with @ianstormtaylor, it sounds like identity is needed. between renders.Slate: 0.50.7
What's the expected behavior?
The docs should be updated to use a ref (or some other stable memo besides useMemo/useCallback/etc). Slate itself could memoize the value passed to it if identity is necessary, or inversion of control could be maintained for the user of Slate to pass a memoized version.
Note:
A simple hook that I wrote can help to initialize a ref if it's expensive to compute. It works similar to useState's lazy initialization, but there wasn't a way to lazily set a ref.
import {useRef, MutableRefObject} from 'react';
The text was updated successfully, but these errors were encountered: