Reputation: 3132
In the process of learning some 'react', i was looking to convert a simple-react component to use redux. In my component depending on some props value i am initializing an array and setting it to the component state.
let my_arr = new Array(this.props.rows);
this.state = {
arr: my_arr
}
Instead of creating & setting my state in the component, i want to use a reducer for this. I'm trying to create a reducer (reducer_arr.js) which will initialize and return this array. My question was, how can i know the size of the array i need to return? Is there anyway to read the props values of that component in my reducer?
export default function board() {
let my_arr = new Array(???);
return my_arr;
}
Upvotes: 1
Views: 698
Reputation: 612
That is not the way React/Redux works - You need to have an action creator which may be calls a service that gets the data for example - and in that action creator you dispatch the type of action you want to perform and reducer will uodate the state depending up on the type of action(which we need to specify) and in turn updates the component with the new state - and the component re-renders -
Upvotes: 1