use useEffect hooks in <BrowserOnly/> issuse
See original GitHub issue🐛 Bug Report
Prerequisites
- [√] I’m using the latest version of Docusaurus.
- [√] I have tried the
npm run clearoryarn clearcommand. - [√] I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages.
Description
When I use useEffect in my development BrowserOnly, the console reports the following error
export default function BlogTagsPostPage(props) {
return (
<BrowserOnly fallback={null}>
{() => {
useEffect(() => {
console.log(11);
}, []);
return <span></span>;
}}
</BrowserOnly>
);
}

Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
React.useEffect Hook – Common Problems and How to Fix ...
The first and probably most obvious option is to remove the dependency from the useEffect dependency array, ignore the ESLint rule, and move...
Read more >Using the Effect Hook - React
We pass a function to the useEffect Hook. This function we pass is our effect. Inside our effect, we set the document title...
Read more >React hook using useEffect updates on web browser but not ...
The problem, which only happens on mobile, is that when hash updates, the surrounding 'squares' get updated images, but the current 'square' ...
Read more >How the useEffect Hook Works (with Examples) - Dave Ceddia
The useEffect hook is the Swiss Army knife of all the hooks. It's the solution to many problems: how to fetch data when...
Read more >The last guide to the useEffect Hook you'll ever need
With useEffect , you invoke side effects from within functional components, which is an important concept to understand in the React Hooks era....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Use this instead:
这是因为你的代码在
require的时候就已经被解析了,所以你应该把整个引入 dependency 的代码放在useEffect里面。另外,useIsBrowser这个钩子你也可能想了解一下