facebookexperimental/Recoil

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

Open

#1,513 创建于 2021年12月22日

在 GitHub 查看
 (4 评论) (5 反应) (0 负责人)JavaScript (19,428 star) (1,151 fork)batch import
help wantednative

描述

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?

贡献者指南

[React Native] "Duplicate atom key"-warning in React Native/Expo · facebookexperimental/Recoil#1513 | Good First Issue