Reactjs 如何使用ComponentWillReceiveProps在React Native中重新呈现平面列表? UNSAFE_组件willmount(){ this.props.EmployeeFetch(); } renderRow(员工){ 返回; } render(){ 返回( ); } } 常量mapStateToProps=状态=>{ const employees=\映射(state.employees,(val,uid)=>{ 返回{…val,uid}; }); 返回{雇员}; } 导出默认连接(MapStateTops,{EmployeeFetch})(EmployeeList);
这里我正在从firebase获取数据。起初它是空的,过了一段时间数据就来了。那么,如何使用Flatlist和ComponentWillReceiveProps()重新呈现新数据呢 您应该使用2返回函数 1哪个返回加载(活动指示器) 2如果数据以任何状态存在,则返回数据Reactjs 如何使用ComponentWillReceiveProps在React Native中重新呈现平面列表? UNSAFE_组件willmount(){ this.props.EmployeeFetch(); } renderRow(员工){ 返回; } render(){ 返回( ); } } 常量mapStateToProps=状态=>{ const employees=\映射(state.employees,(val,uid)=>{ 返回{…val,uid}; }); 返回{雇员}; } 导出默认连接(MapStateTops,{EmployeeFetch})(EmployeeList);,reactjs,firebase,react-native,redux,react-redux,Reactjs,Firebase,React Native,Redux,React Redux,这里我正在从firebase获取数据。起初它是空的,过了一段时间数据就来了。那么,如何使用Flatlist和ComponentWillReceiveProps()重新呈现新数据呢 您应该使用2返回函数 1哪个返回加载(活动指示器) 2如果数据以任何状态存在,则返回数据 UNSAFE_componentWillMount(){ this.props.EmployeeFetch(); } renderRow(employee){ return
UNSAFE_componentWillMount(){
this.props.EmployeeFetch();
}
renderRow(employee){
return <ListItem employee={employee}/>;
}
render(){
return(
<FlatList style={{flex:1,height:100}}
data = {this.props.employees}
/>
);
}
}
const mapStateToProps=state=>{
const employees = _.map(state.employees,(val,uid)=>{
return {...val,uid};
});
return {employees};
}
export default connect(mapStateToProps, {EmployeeFetch})(EmployeeList);
构造函数(道具){
超级(道具);
this.state={isLoading:true};
}
render(){
if(此.state.isLoading){
报税表(
)}
返回(
);
常量mapStateToProps=状态=>{
const employees=\映射(state.employees,(val,uid)=>{
返回{…val,uid};
});
如果(雇员){
this.state.isLoading=false;
}
返回{雇员};
}
注意:不要忘记导入react组件
而且,如果您使用的是react navigation,那么请尝试使用来导航数据获取api的事件,而不是使用不安全的组件WillMount()或找到其他解决方案。因此
组件WillReceiveProps
已被弃用,您应该使用getDerivedStateFromProps
您可以将其与示例一起使用:
constructor(props) {
super(props);
this.state = { isLoading: true};
}
render() {
if(this.state.isLoading){
return(
<View>
<ActivityIndicator size="large" color="#0c9"/>
</View>
)}
return(
<FlatList style={{flex:1,height:100}}
data = {this.props.employees}
/>
);
const mapStateToProps=state=>{
const employees = _.map(state.employees,(val,uid)=>{
return {...val,uid};
});
if(employees){
this.state.isLoading = false;
}
return {employees};
}
然后在渲染中
:
static getDerivedStateFromProps(props, state) {
const { employees } = this.props;
return employees;
}
哪个数据库在使用firestore或realtime database Real time database也在使用react redux来管理状态。我不是在使用状态,而是redux。你能详细说明一下我的代码吗?我是一个新手RN@BestOFBest请更新你的文章与你的整个组件,以便我可以看到道具等。
render() {
const { employees } = this.props;
// then use map(employees)
}