UseonViewWillEnter未按预期工作-Ionic、ReactJS、Context API
我的应用程序中有一个屏幕,它使用上下文API还原程序从服务器上获取加载数据。为此,我设置了如下代码。这是一个功能组件UseonViewWillEnter未按预期工作-Ionic、ReactJS、Context API,reactjs,ionic-framework,context-api,Reactjs,Ionic Framework,Context Api,我的应用程序中有一个屏幕,它使用上下文API还原程序从服务器上获取加载数据。为此,我设置了如下代码。这是一个功能组件 const refreshView = () => { propertyDispatch({ type: "GETPROPERTYS", mobileNumber: contextValue.mobileNumber, }); }; useIonViewWillEnter(() => { r
const refreshView = () => {
propertyDispatch({
type: "GETPROPERTYS",
mobileNumber: contextValue.mobileNumber,
});
};
useIonViewWillEnter(() => {
refreshView();
});
<IonContent fullscreen>
{console.log({ render: propertyState })}
{propertyState.properties! && (
<IonGrid>
{propertyState.properties!.map((property: any) => (
<IonRow key={property.propertyID}>
<IonCol>
我已经证实我的调度方法运行良好。但是,新创建的数组在视图的返回方法中为空。更奇怪的是,如果我控制台记录propertyState,我可以看到数组中的一条记录,但是如果我控制台记录propertyState.properties,我什么都看不到
console.log(propertyState)
日志(propertyState.properties)
switch (action.type) {
case "GETPROPERTYS": {
propertyservices.getPropertys(action.mobileNumber).then((response) => {
let propes = [...response.data[0]];
console.log(props);
newData.properties = [];
propes.map((p) => {
let property = {};
property.name = p.PropertyName;
newData.properties.push(property);