I have a component App() which takes some props, called data. That App component manages its state via useReducer. Depending on the state of my reducer, I show/hide certain data from the data prop. My reducer also calculate new state depending on what's in data. So for example, to get a new id, my reducer needs to go through data and find the next id.
const App = ({ data }) => {
//...
const reducer =
(state, action) => {
switch (action.type) {
case 'NEXT_TAB': {
let nextTabIndex = state.activeTab + 1;
let nextId = data.tabs[nextTabIndex].id; //<==== Worried about this line here, accessing data prop
return {
...state,
state.activeTabId: nextId
};
}
default:
return state;
}
}
//....
const [myState, dispatch] = useReducer(reducer, state);
//....
As I implemented it here, my App component receives data as props.
In my reducer, I access those props:
let nextId = data.tabs[nextTabIndex].id
My question is whether this goes against the idea of a reducer to work with & utilise the received props? I could, alternatively, pass the data props to my reducer, every time I call an action. However, I am worried that this will make everything slower and unnecessarily complex?