Im trying to set the initial state of a redux state based on an object item param straight inside the redux saga state. It has to be in this file, (long story) so I decide to put it in this file. So my first thought is to write a function in the redux file to do the job. However, not sure how to access the state that I will need that is from another redux file. I did research and saw that you can use the following syntax to do so in generator functions
const state = yield select();
So I tried this in a vanilla javascript function and as expected did not work. Is there any way where I can do the following?
const initialState = {
currentAccountId: fetchAndReturnId(),
currentName: '',
};
function fetchAndReturnId() {
const state = yield select();
const { accounts } = state.global.accounts;
const charityAccount = accounts.find(acc => acc.type === 'charity');
return charityAccount.id;
}
Just wondering if anyone else had any other solutions. Thanks!