我是react-native的新手,想知道window.___INTITIAL_STATE__
的工作。
main.js
import React from "react";
import createStore from "./store/createStore";
import AppContainer from "./AppContainer";
export default class Root extends React.Component {
renderApp() {
const initialState = window.___INTITIAL_STATE__;
const store = createStore(initialState);
return <AppContainer store={store} />;
}
render() {
return this.renderApp();
}
}
createStore.js
import { createStore, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import makeRootReducer from "./reducers";
import { createLogger } from "redux-logger";
const log = createLogger({ diff: true, collapsed: true });
export default (initialState = {}) => {
const middleware = [thunk, log];
const enhancers = [];
const store = createStore(
makeRootReducer(),
initialState,
compose(
applyMiddleware(...middleware),
...enhancers
)
);
return store;
};