[React Native] "Duplicate atom key"-warning in React Native/Expo
#1513 opened on Dec 22, 2021
Description
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?