-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fix(useWebSocket): add init phase to pass React 18 Strict Mode #1923
base: master
Are you sure you want to change the base?
Conversation
Thanks for your contribution ~ |
I appreciate your review. A patch has been committed to my source code for your comments. The initialization of the // The following is the source code of the hook `useUnmountedRef`
import { useEffect, useRef } from 'react';
const useUnmountedRef = () => {
const unmountedRef = useRef(false);
useEffect(() => {
unmountedRef.current = false; // Here, the unmountedRef is set to false at every mount process
return () => {
unmountedRef.current = true;
};
}, []);
return unmountedRef;
};
export default useUnmountedRef; But I decided to edit my code after all. It's because, in my origin code, the initialization of the internal states is separated into different places, which could be confusing. PTAL. Thx. |
I see, the code I see is being merged, #1928
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A problem I found while I'm writing test cases is that onError
is triggered
// demo
const Demo = () => {
// ...
useWebSocket(
'wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV¬ify_self',
{
+ onError: (err) => console.log('onError', err),
},
);
}
export default () => {
+ <StrictMode>
<Demo />
+ </StrictMode>;
};
@KONY128 Are you still following up on this PR? |
v3.7.4 遇到同样问题 |
🤔 This is a ...
🔗 Related issue link
Related problems, root cause analysis and description of this fix is in #1922
💡 Background and solution
📝 Changelog
useWebSocket
is not available in React 18 Strict ModeuseWebSocket
在 React 18 Strict Mode 下不可用的问题☑️ Self Check before Merge