実現したいこと
以下のエラーを解消したいです。
この事象について、以下のサイトを参照しましたがRecoilライブラリは現在使用すべきではないのでしょうか?
使用すべきでない場合、useStateやuseReducerを使用すべきなのでしょうか。
ご存知の方、ご教示頂きたく思います。
宜しくお願いします。
・参照サイト
https://github.com/facebookexperimental/Recoil/issues/2318
発生している問題・分からないこと
上記同様になります。
エラーメッセージ
error
1Cannot destructure property 'ReactCurrentDispatcher' of 'react__WEBPACK_IMPORTED_MODULE_0___default(...).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' as it is undefined. 2TypeError: Cannot destructure property 'ReactCurrentDispatcher' of 'react__WEBPACK_IMPORTED_MODULE_0___default(...).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' as it is undefined. 3 at currentRendererSupportsUseSyncExternalStore (http://localhost:3000/static/js/bundle.js:62965:5) 4 at useRecoilValueLoadable (http://localhost:3000/static/js/bundle.js:67055:26) 5 at useRecoilValue (http://localhost:3000/static/js/bundle.js:67072:20) 6 at useRecoilState (http://localhost:3000/static/js/bundle.js:67114:11) 7 at RecoilCounter (http://localhost:3000/static/js/bundle.js:6235:83) 8 at react-stack-bottom-frame (http://localhost:3000/static/js/bundle.js:56724:18) 9 at renderWithHooks (http://localhost:3000/static/js/bundle.js:48041:20) 10 at updateFunctionComponent (http://localhost:3000/static/js/bundle.js:49310:17) 11 at beginWork (http://localhost:3000/static/js/bundle.js:49928:16) 12 at runWithFiberInDEV (http://localhost:3000/static/js/bundle.js:45269:14)
該当のソースコード
index.js
1import ReactDOM from 'react-dom/client'; 2import './index.css'; 3import reportWebVitals from './reportWebVitals'; 4import RecoilCounter from './practiceFiles/RecoilCounter.js'; 5import { RecoilRoot } from 'recoil'; 6 7const root = ReactDOM.createRoot(document.getElementById('root')); 8root.render( 9 <RecoilRoot> 10 <RecoilCounter /> 11 </RecoilRoot> 12) 13
atom.js
1import { atom } from "recoil"; 2 3// stateを保持するAtom 4export const counterAtom = atom({ 5 key: "counterAtom", 6 default: 0 7}); 8 9export default counterAtom;
RecoilCounter.js
1import { useRecoilState } from "recoil" 2import { counterAtom } from "../store/atom" 3 4export default function RecoilCounter() { 5 // state値をAtomから取得 6 const [count, setCount] = useRecoilState(counterAtom); 7 8 // カウントボタン押下時に処理 9 const handleClick = () => { 10 setCount(c => c + 1); 11 } 12 13 return ( 14 <> 15 <button type="button" onClick={handleClick}>カウント</button> 16 <p>{count}回、クリックされました。</p> 17 </> 18 ) 19}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
https://github.com/facebookexperimental/Recoil/issues/2318
上記サイトにより、コード修正で解決するより、Recoilを使用しない方向で進めた方が良いのではないかと思っています。
補足
特になし

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2025/02/09 03:00