为什么没有调用mapStateToProps

时间:2018-01-31 02:42:31

标签: javascript reactjs react-redux

我把头撞在墙上。我已经在React + Redux上运行了一段时间,然后我使用Chrome删除了我的localStorage,一切都变得混乱。现在我无法通过mapStateToProps来调用,所以即使减速器处于正确的状态,我也没有获得道具。

我已经阅读了Redux文档中的故障排除部分,因为没有调用mapStateToProps,但它似乎主要归结为不要改变你的状态。为了确保我没有,我将减速器代码减少到几乎没有什么可以排除可能性。这是:

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

export const rootReducer = (state = {}, action) => {
   switch (action.type) {
       case 'SET_CURRENT_USER':
           return Object.assign({}, state, {user: action.user});
           break;
       default:
           return state
    }
    return state
}

const store = createStore(
    reducer,
    applyMiddleware(middleware), 
    autoRehydrate()
)

const reducer = combineReducers({
  rootReducer: rootReducer,
  routing: routerReducer,}
)

使用@connect(mapStateToProps,mapDispatchToProps)连接我的一个测试组件。我过去没有遇到任何问题,我使用更标准的非装饰器实现测试了几次,但没有骰子。

任何想法都会非常有用。

这里减少了组件:

@connect(mapStateToProps, mapDispatchToProps)
export class TestComponent extends React.Component {
    constructor(props) {
        super(props);
        autobind(this);
    }

    componentDidMount() {
        store.dispatch(setCurrentUser({id:1}))
    }

    render() {
        return (
            <div>

            </div>
        )
    }
}
export class TestPage extends React.Component {
    constructor(props) {
        super(props);
        autobind(this);

        }

    render() {
       return (
           <div>
               <TestComponent />
           </div>
        )
    }


}

1 个答案:

答案 0 :(得分:1)

试试这个:

rows = X_train.shape[0]
rem = rows%1000
no = rows/1000
i = 0

while (i <= no*1000) :
    dst_mat = euclidean_distances(X_train[i:i+1000, :], X_test)
    condition = np.any(dst_mat <= 0.005, axis = 1)
    index = np.where(condition == True)
    index = np.add(index, i)
    print(index)
    print(dst_mat)
    i+=1000

希望它有所帮助。!