Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Usecontext返回未定义-反应本机_Javascript_Reactjs_React Hooks_React Context - Fatal编程技术网

Javascript Usecontext返回未定义-反应本机

Javascript Usecontext返回未定义-反应本机,javascript,reactjs,react-hooks,react-context,Javascript,Reactjs,React Hooks,React Context,我想要一个带有从后端获取的数据列表的页面。列表中的每个值都有一个“获取更多详细信息”按钮,单击该按钮可以显示每个项目的单个数据。我正在尝试使用useContext钩子将items数据传递到下一页,但数据在下一页中显示为未定义 GetOrders.js export const orderContext = React.createContext() const GetOrders = ({ navigation }) => { renderOrdersData = ({ item })

我想要一个带有从后端获取的数据列表的页面。列表中的每个值都有一个“获取更多详细信息”按钮,单击该按钮可以显示每个项目的单个数据。我正在尝试使用useContext钩子将items数据传递到下一页,但数据在下一页中显示为未定义

GetOrders.js

export const orderContext = React.createContext()
const GetOrders = ({ navigation }) => {

renderOrdersData = ({ item }) => {
    return (
      <orderContext.Provider value={ item }>

      <TouchableOpacity onPress={() => showAddress(item)} style={[styles.item]}>
        <View style={styles.textstyles}>
       
          <View style={styles.contentstyle}>
            <Text style={styles.title}>Name: {item.customer.name}</Text>
            <Text style={styles.title}>Quantity: {item.orders.quantity} </Text>
            <Text style={styles.title}>Contact: {item.customer.contact}</Text>
          </View>
        
          <View style={styles.paidbuttonstyles} >
            <Button title="Get more details"
              onPress={() => navigation.navigate('CustomerOrder') }
            />
          </View>
        </View>
      </TouchableOpacity>
      </orderContext.Provider>


    );
  };

return (
        <SafeAreaView style={styles.container}>
          <Text style={styles.textcss}> Your Pending orders are </Text>
          <FlatList
            style={styles.listcolor}
            data={orders}
            renderItem={renderOrdersData}
          />
        </SafeAreaView>
      );
}


如果有任何帮助,我们将不胜感激?谢谢

您在哪里使用过
客户订单
?您的
CustomerOrder
组件必须位于
orderContext.Provider
下。是。请检查getOrder.js文件中的返回语句。标签以何处开始?我没有看到。您正在使用导航器导航到该路线。但我不一定看到您在哪里定义了组件?领航员是否支持向路线传递道具?我想你可以通过导航器把数据传给你的路线。谢谢。通过导航器传递数据起作用了。
import { orderContext } from './GetOrders'
const CustomerOrder = ({ navigation }) => {

  let items = useContext(orderContext)


  showAddress = () => {

    console.log(" inside showadress" + items);

    console.log(" inside showadress json " + JSON.stringify(items));
   }

   return (
     <View style={styles.dismissbuttonstyles} >
        <Button title="Get Customer address"
          onPress={() => showAddress()}
        />
      </View>
   );
}
[Tue Sep 01 2020 19:20:50.443]  LOG       inside showadressundefined
[Tue Sep 01 2020 19:20:50.459]  LOG       inside showadress json undefined
[Tue Sep 01 2020 19:20:50.461]  ERROR    TypeError: undefined is not an object