Redux Map Store的道具名称

时间:2019-03-02 10:59:14

标签: reactjs redux

Redux Map Store的道具名称。

const mapStore = (state, ownProps) => {
  const name = ownProps.name;
  return {
    value: state.[name] //<= help here
  };
};

2 个答案:

答案 0 :(得分:0)

我猜您的问题是.之后的状态,这应该可以解决您的问题。

const mapStore = (state, ownProps) => {
  const name = ownProps.name;
  return {
    value: state[name] // No period after state
  };
};

答案 1 :(得分:0)

const mapStore = (state, ownProps) => {
  const name = ownProps.name;
  return {
    value: state.name //assuming state is an object with a key - name
  };
};