facebookexperimental/Recoil

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

开放

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

 (4 条评论) (5 个反应) (0 位负责人)JavaScript (1,151 个派生)batch import
help wantednative

仓库指标

星标
 (19,428 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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?

贡献者指南