Non-serializable values in navigation state

Viewed 2071

I'm finding it impossible to resolve this warning. I'm passing my list item as a param to the subsequent navigation screen "details" in order to display information about the user selected string from a list. I understand that I am passing a react object read"params.coinID.$$typeof (Symbol(react.element))", but I'm unable to find the proper methodology for passing this user selected parameter.

        <SafeAreaView style ={styles.container}>
        <Text style ={styles.title}>New Hot Tokens</Text>
        <FlatList
        data={listItems}            
        renderItem={({item}) => <Text style={styles.item}
        onPress={() => {
              navigation.navigate('Details', {coinID: (item)
              }); 
            }}  
        >{`${item.key}`}</Text>}/>
        </SafeAreaView>
  );  
}

function DetailsScreen({route, navigation}) {

const { coinID } = route.params;

console.log(coinID.key)

const { loading: coinLoading, error, data: coinData } = useQuery(COIN_INFO, {
          variables: {
                  coinForQuery: coinID.key},
                  pollInterval: 15000,
                  fetchPolicy: 'network-only',
                  notifyOnNetworkStatusChange: true
  }
);
1 Answers

As quoted in the documentation: https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state

If you don't use state persistence or deep link to the screen which accepts functions in params, then the warning doesn't affect you and you can safely ignore it. To ignore the warning, you can use YellowBox.ignoreWarnings.

But the general solution(without using Redux ) is to use Context API to store data in the parent Component.

Please follow this tutorial for help: https://dev.to/emeka/state-management-in-react-native-using-context-14no

Related