gpt4 book ai didi

javascript - -React Native,从A.js到B.js传递状态数据的方式是什么

转载 作者:行者123 更新时间:2023-11-28 03:42:57 26 4
gpt4 key购买 nike

我正在寻找将状态数据从 A.js 传递到 B.js 的方法

so I want to retrieve "DEF " as title[1] from A.js to B.js

A.js

export default class A extends Component {
constructor(props) {
super(props)
this.state = {
title: ["ABC","DEF","GHI"]
};
}
render(){return(<Text>{this.state.title[1]}</Text>)}
module.exports = A;

B.js

import {A} from "./A"  
export default class B extends Component {
render(){return(<Text>{A.state.title[1]?? // not sure about this part
}</Text>)}
}

最佳答案

为您定制:

import {B} from './B'
export default class A extends Component {
constructor(props) {
super(props)
this.state = {
title: ["ABC","DEF","GHI"]
};
}
render(){return(<B titlePropForB={this.state.title})}
module.exports = A;


export default class B extends Component {
render(){
console.log(this.props.titlePropForB);
return(<Text>{this.props.titlePropForB[1]}</Text>)}
}

关于javascript - -React Native,从A.js到B.js传递状态数据的方式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48777306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com