I'm rather a python Guy but I've been trying react for some. This whole react ecosystem evolves so fast that after a few months of break I cannot recognize the word anymore :)
Trying to write simple geo mapping app: using: react-boilerplate-cra-template To simplify things I have
<MyHomePage>
<Div>
<MyMapApplet/>
<MyFilter>
<RadioButtonGroup>
<RadioButton/>
<RadioButton/>
</RadioButtonGroup>
</MyFilter>
</Div>
</MyHomePage>
Question what are best practices regarding reducers and selectors from other components.
I have a simple reducer (createSlice in slice.ts) / selector (reselect selectors.ts) defined on RadioButtonGroup
that sets the value of currently selected radio button. That works fine.
// The initial state of the RadioRatGroup container
export const initialState: ContainerState = {
netrat: '4G',
};
const radioRatGroupSlice = createSlice({
name: 'radioRatGroup',
initialState,
reducers: {
setNetRat(state, action: PayloadAction<any>) {
state.netrat = action.payload;
},
},
});
and selector
const selectDomain = (state: RootState) => state.radioRatGroup || initialState;
export const selectNetRat = createSelector(
[selectDomain],
radioRatGroupState => radioRatGroupState.netrat,
);
Can I just include e.g same Selector in other components like eg. MyMapApplet
by using
import { selectNetRat } from 'app/components/RadioButtonGroup/selectors';
or is it a bad manner that I should avoid?
How shall get the reference (pointer?) to the value set by some other component and saved to store?
As far as I understood Redux would be a great "centralized" store to keep track of the state of the application (saved values/objects). In boilerplate / sliced / redux-toolkit approach everything seems to be a bit "decentralized" again?
Thanks for clarification and I'm really sorry if I mix some of the things.