I am using functional component and trying to achieve MVVM. I want to get updated value of redux state without using useSelector hook
Here is my code
model.js
export class Model {
getData = () => {
return store.getState().mReducer.jsonData
}
setData = (data) => {
store.dispatch(setData(data)) // storing in redux for further use
}
}
ViewModel.js
export class ViewModel {
onChangeTextHandler = (text) => {
this.model.setData(tmp)
}
}
View.js
export const View = () => {
const vm = useMemo(() => new ENReceivingViewModel(), [])
const model = useMemo(() => new ENREceivingModel(), []);
//IF I use this line then rerender happens otherwise nothing happens
//const { selectedOption, jsonData } = useSelector(state => state.ReceivingReducer)
return (
<TextInput value = {model.getData()[0]}
onChangeText={vm.onChangeTextHandler} />
)}
model.getData()[0]
instead ofmodel.data[0]
? – Measured