pmndrs / valtio

🧙 Valtio makes proxy-state simple for React and Vanilla
https://valtio.dev
MIT License
8.84k stars 248 forks source link

does not work in react native application #666

Closed llz383455526 closed 1 year ago

llz383455526 commented 1 year ago

I had used valtio in web applications, it works fine! But in React Native App, I encountered a problem。 version: 1.10.1

In react native project, when i mutate object in store, show error: TypeError: target property is non-configurable and non-writable, and set trap value differs from target property value

// store/NewsCreate.ts

const initNews = {
  replyedTimeline: undefined,   // type is undefined | {ts:'', user: {name: '', age: ''}}
};
export const newsStore = proxy(initNews);
// screen/index.ts

import { newsStore } from '@/store/NewsCreate';

...
const news = useSnapshot(newsStore);
useEffect(() => {
    if (route.params?.newsItem ) {
      newsStore.replyedTimeline = route.params.newsItem;  // problem happened here
    }
  }, [route.params?.newsItem]);
dai-shi commented 1 year ago

Let's continue it in #665.