Recoil icon indicating copy to clipboard operation
Recoil copied to clipboard

[React Native] "Duplicate atom key"-warning in React Native/Expo

Open Bosskee opened this issue 3 years ago • 3 comments

Hello. I have previously used Recoil in web applications without problems, and I love it's approach to globalized state. But I'm now implementing Recoil in a React Native/Expo app, and have encountered a warning that keeps following me. This is my code:

Where atom is created:

// globalState.js

const { atom } = require("recoil");

export const priceDataState = atom({
    key: "priceDataState",
    default: null
  });

Where atom is used:

// Screen.js

import { useRecoilState } from 'recoil';
import { priceDataState } from "../globalState";
export default function HomeScreen({ navigation }) {
const [priceData, setPriceData] = useRecoilState(priceDataState);
return(
<Text>{priceData}</Text>
)
}

When I do this, I get the following warning in Expo GO: Console warning: Duplicate atom key "priceDataState". This is a FATAL ERROR in production. But it is safe to ignore this warning if it occurred because of hot module replacement

An interesting and possibly important note is that the warning only seems to occur if I navigate to globalState.js in VSCode and save the document, which results in a hot reload in Expo GO. The warning mentions something about "hot module replacement", which might be related to hot reload?

Thankful for any input on this. Is it a bug?

Bosskee avatar Dec 22 '21 22:12 Bosskee

It seem like this would be addressed by now. Getting this in Stackblitz and other environments. Not using Next.js.

ryanwellsdotcom avatar Mar 06 '22 02:03 ryanwellsdotcom

Me to have this problem and I don't find how I can go on next steps. Who and how maked it?

chisto4 avatar Mar 23 '22 10:03 chisto4

How can we use this in production with this bug?

nikitph avatar May 28 '22 06:05 nikitph

There is a way to disable this error in 0.7.6. Please confirm it

https://github.com/facebookexperimental/Recoil/releases/tag/0.7.6

0oooooooo0 avatar Oct 22 '22 23:10 0oooooooo0