ABOUT ME

Today
Yesterday
Total
  • [react] useEffect가 두 번 실행되는 현상
    react+vue 2022. 9. 23. 15:52

    react Strict모드 때문인데

    next.config.js가 있다면 그 안에 reactStrictMode를 false로 수정하면 된다

    나 같은 경우에는 없었는데 찾아보니 index.js에서 설정을 변경할 수 있었다.

    • index.js
    import React from 'react';
    import ReactDOM from 'react-dom/client';
    import './index.css';
    import App from './App';
    import reportWebVitals from './reportWebVitals';
    
    const root = ReactDOM.createRoot(document.getElementById('root'));
    root.render(
      
        
      
    );
    
    // If you want to start measuring performance in your app, pass a function
    // to log results (for example: reportWebVitals(console.log))
    // or send to an analytics endpoint. Learn more: <https://bit.ly/CRA-vitals>
    reportWebVitals();
    

    import React from 'react';
    import ReactDOM from 'react-dom/client';
    import './index.css';
    import App from './App';
    import reportWebVitals from './reportWebVitals';
    
    const root = ReactDOM.createRoot(document.getElementById('root'));
    root.render(
      
        
      
    );
    
    // If you want to start measuring performance in your app, pass a function
    // to log results (for example: reportWebVitals(console.log))
    // or send to an analytics endpoint. Learn more: <https://bit.ly/CRA-vitals>
    reportWebVitals();
    

    로 수정해 주었더니 해결됐다.

    'react+vue' 카테고리의 다른 글

    [react] props (2)  (1) 2022.09.24
    [react] props (1)  (0) 2022.09.23
    [react] styled-components  (0) 2022.09.23
    [react] useRef  (0) 2022.09.22
    [react] useMemo  (0) 2022.09.22

    댓글

Designed by Tistory.