【发布时间】:2018-08-09 17:18:12
【问题描述】:
这是我第一次用这个堆栈组合一个新的应用程序。以前,我在另一个已经安装了管道的演出中工作了一个继承的。我的道具未定义,我需要知道原因。也请提出建议。这是删减的代码:
index.js
const store = createStore(rootReducer);
render(<Root store={store} />, document.getElementById("root"));
Root.js
const Root = ({ store }) => (
<Provider store={store}>
<Router>
<Route path="/:filter?" component={App} />
</Router>
</Provider>
);
Root.propTypes = {
store: PropTypes.object.isRequired
};
export default Root;
App.js
const App = ({ classes }) => ( // SHOULDN'T THIS BE DESTRUCTURED FROM PROPS?
<div className={classes.root}> // <== UNDEFINED...WHY NO PROPS?
<Grid container spacing={24}>
<Grid item xs={12}>
<AppBar />
</Grid>
</Grid>
</div>
);
export default withRoot(compose(connect())(App));
withRoot.js (从 Material-UI 创建一个默认主题)
const theme = createMuiTheme({
palette: {
type: "dark"
},
typography: {
fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
fontSize: 14,
fontWeightLight: 300,
fontWeightRegular: 400,
fontWeightMedium: 500
}
});
function withRoot(Component) {
function WithRoot(props) {
// MuiThemeProvider makes the theme available down the React tree
// thanks to React context.
return (
<MuiThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<Component {...props} />
</MuiThemeProvider>
);
}
return WithRoot;
}
export default withRoot;
【问题讨论】:
-
连接中没有 mapStateToProps - 您应该通过部分存储
标签: javascript reactjs redux react-redux material-ui