score:1

Accepted answer

there's no this with a functional component. to access the props you can change it to this:

const todoapp = (props) => {
    console.log(props)
    return (
        <div>
            some text1
        </div>
    )
}

score:1

mapstatetoprops maps the some parts of your redux state to props of your react component.

state comes from your store. in fact, you can take a look at your current state at any point by calling store.getstate(). when you do createstore(todos), this creates the state based on the todos reducer. as you can see in your todos reducer, your initial state comes from stateobject, which is defined up top.

so, back to mapstatetoprops. all you need to do in that functions is to return the object, where keys will be the props and values will be the values obtained from the redux state. here's an example of mapstatetoprops:

const mapstatetoprops = function (state) {
    return {
        propname: state
    }
}

now when you do the console.log(this.props) inside render(), you can see the whole state being stored inside this.props.propname. that is achieved by mapstatetoprops.

a little bit of theory on this: each time an action is dispatched, every mapstatetoprops you have in your app is called, props are applied to every component you created, and if any props have changed, that component will re-render. this kind of behaviour is provided for you via connect function. so you don't have to implement this behaviour for every component: all you need to do is to apply it like so: const connectedcomponent = connect(mapstatetoprops)(somecomponent) and use connectedcomponent instead of somecomponent.


Related Query

More Query from same tag