A
A
Alexander Ivanov2018-02-17 14:55:19
React
Alexander Ivanov, 2018-02-17 14:55:19

Why does map swear at redux in react?

render(){
// так не работает
        console.log(this.props.testT);
        const numbers = this.props.testT;
        const listItems = numbers.map((number, index) =>
            <li key={index}>{number}</li>
        );
//так работает
        const vals= ["Param","New"]; 
        const listItems = vals.map((vals, index) =>
            <li key={index}>{number}</li>
        );
        console.log(vals);
        return(
            <div>
                <ul>
                    {listItems}
                </ul>
            </div>
        )}

... 

export default connect(
    state => ({
        testT: state
    }),
    dispatch => ({})
)(App);

the values ​​of vals and this.props.testT are absolutely identical in the console log
and the output is:
Uncaught TypeError: numbers.map is not a function
I follow the materials https://www.youtube.com/watch?v=76UKD-4pVis&index=. ..
What could be the root of the problem?
______
reducer
const initialState = [
    "Param",
    "New"
];
function test(state = initialState, action) {
    // console.log(action)
    if(action.type === 'ADD_TEST'){
        return [
            ...state,
            action.name
        ]
    }
    return state;
}

const store = createStore(
    test,
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);

Norms are also transferred from state

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ivanov, 2018-02-17
@cimonlebedev

I found the problem is that I have __REDUX_DEVTOOLS_EXTENSION__ connected,
it saved the old state from before launch and because of this it conflicts.
Apparently in REDUX_DEVTOOLS you can somehow clear the cache.

R
Roman Aleksandrovich, 2018-02-17
@RomReed

Show reducer please

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question