存储和服务器不同步

时间:2019-07-07 17:28:25

标签: javascript reactjs redux axios redux-thunk

当我使用axios的PUT方法并将I PUT数据放置在服务器上时,数据被放入旧数据中并且服务器未更新,但是存储在执行操作时发生变化,看来存储和服务器不同步。

apiCaller.js

class Pizza {

    @MaxGramsOfCheese(max = "${application.pizza.cheddar.max-grams}")
    int gramsOfCheddar;

    @MaxGramsOfCheese(max = "${application.pizza.mozerella.max-grams}")
    int gramsOfMozerella;

}

action / index.js

const API_URL = 'https://s39o5.sse.codesandbox.io' ;
export default function callApi(endpoint, method = 'GET', body){
    return axios({
        method: method,
        url: `${Config.API_URL}/${endpoint}`,
        data: body
    }).catch(err => {
        console.log(err);
    });
};

components / ListItems.js

export const fetchIsActiveList = (users)=>{
    return dispatch =>{
        return callApi (`list/${users.id}`,'PUT',users).then(res =>{
            dispatch(itemRequestActive(res.data))
        }) ;
    }
}
export const itemRequestActive = (id) => {
    return {
        type: ITEM_REQUEST_ACTIVE,
        id
    }
}

reducers / ListItem

componentDidMount() {
  var { match } = this.props;
  var id = match.params.id;
  this.props.fetchAllListItem(id);
} 

onAccept(user) {
  this.props.fetchIsActive(user);
} 

render { 
     const { user } = this.props;
  return (){
  <div>
  { user.map((user, index) =>(
 ...
    <h5 onClick={() => this.onAccept(user)} >Accept</h5>
    ))}

   </div>
  }
} 

const mapStateToProps = (state) => {
  return {
    user: state.listItems,
  }
} 

const mapDispatchToProps = (dispatch) => {
  return {
    fetchAllListItem: (id) => {
      dispatch(actFetchListItemRequest(id))
    },
    fetchIsActive: (user) => {
      dispatch(fetchIsActiveList(user));
    }
  }
}

0 个答案:

没有答案