简体   繁体   English

将数据从子组件传递给另一个子组件

[英]Pass data from child component to another child

I'm using React JS我正在使用反应 JS

I want to pass data from child component to another child component.我想将数据从子组件传递到另一个子组件。

-App -应用程序

-- Home - 家

--- Filter ( Here is I need to to pass data from Filter component To Card component it's useState value) --- 过滤器(这是我需要将过滤器组件中的数据传递给卡片组件,它是 useState 值)

--- Card ( Here I need to resive data ) --- 卡(这里我需要重新存储数据)

Thre are two ways to solve this problem:有两种方法可以解决这个问题:

1 (I'd recommend for a smaller project): Just keep the state that needs to be shared in the parent component and pass it to the childs as a prop. 1(我建议较小的项目):只需保留需要在父组件中共享的状态并将其作为道具传递给子组件。 You can update the state by creating a callback function in the parent component and calling it from the cild (after passing it as a prop aswell)您可以通过在父组件中创建回调函数并从 cild 调用它来更新状态(在将其作为道具传递之后)

2: Use a state management libary like react-redux 2:使用像react-redux这样的状态管理库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM