سلام من با استفاده از fetch اطلاعاتی رو دریافت میکنم مثلا id,body,title در یک فایل جدایی (http_example.js)
حالا میخوام این اطلاعاتی که دریافت میشه که داخل state هستش در یک کامپوننت دیگه استفاده کنم (Home.js)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
class HttpExample extends Component { state = { data: '' } componentDidMount = () => { fetch('https://jsonplaceholder.typicode.com/posts/1', { method: 'GET' }) .then((response) => response.json()) .then((responseJson) => { console.log(responseJson); this.setState({ data: responseJson }) }) .catch((error) => { console.error(error); }); |
}
در این کد اطلاعات id body title دریافت میشه خالا میخوام این state رو در یک کد دیگه(Home.js) استفاده کنم.
Home.js
<Text>this.state.id=</Text>