Я пытаюсь добиться SSR с помощью Adonis JS +act-redux и планирую передать предварительно загруженные значения сервера в первоначальное создание хранилища резервов.
// server.js(entry point of ssr)
import store from 'providers/store';
...
// initialState = { auth: authenticated: false }
const initialStore = store(initialState); // initialState is received here. refer below for store creation
...
// but when this is processed. It returns the default
// state instead of intended value.
// expected: { auth: authenticated: false }
// received: { auth: authenticated: true } - the default value in rootReducer
const preloadedState = initialStore.getState();
// providers/store.ts
...
export default (preloadedState: any) => createStore(
rootReducer,
preloadedState,
composeEnhancers(applyMiddleware(...middleware)),
);
// reducers/index.ts
import { combineReducers } from 'redux';
import auth from './auth';
export default combineReducers({
auth,
});
// reducers/auth.ts
const INITIAL_STATE: any = {
authenticated: true,
};
export default (state = INITIAL_STATE, action: any) => {
switch (action.type) {
default:
return state;
}
};
Если вас интересует полный исходный код: https://github.com/crrmacarse/adonis-react-ts-boilerplate/tree/authentication