This website uses cookies in order to provide better service to our customers. If you agree to our use of cookies, please click the "Accept" button.
For more information on our cookie policy, please see the "Terms"
logo image

Recoilを使用時に、<RecoilRoot>入れ忘れでエラー発生

Icon representing a data.
2021-11-11
Icon show updated_at
2021-12-10
1
Twitter icon.
Next.js
Recoil

Precondition

  • Recoilを使用
  • プロジェクト内ですでに、useSetRecoilState等を使用済み

Fact

ブラウザのコンソールに以下のようなエラーコードが吐き出される。

Error log or Error Massage

Uncaught (in promise) 
Error: This component must be used inside a <RecoilRoot> component.

Cause

単純に_app.jsにを入れ忘れていたため。

Method

_app.jsにを挿入する。

Remarks

import * as React from 'react';
import { RecoilRoot } from 'recoil';

export default function MyApp(props) {
  const { Component } = props;

  return (
    <RecoilRoot>
        <Component {...pageProps} />
    </RecoilRoot>
  );
}
在宅専門のフリーランスエンジニアをしています。 得意言語はVBAです。Next.jsとTypescriptを鍛錬中。
Area to place ads.
Area to place ads.
Comments
Icon representing a avatar.
Kawa
Icon representing a data.
2021-12-08

Recoilあまり詳しくないので参考にさせていただきます!!!!

Environment Library tools

Next.js
Recoil
在宅専門のフリーランスエンジニアをしています。 得意言語はVBAです。Next.jsとTypescriptを鍛錬中。