React / Redux:我的道具在哪里?

时间:2018-08-09 17:18:12

标签: javascript reactjs redux react-redux material-ui

这是我第一次将新应用与此堆栈放在一起。以前,我在另一个已经建立了管道的演出中处理一个继承的文件。我的道具是不确定的,我需要知道为什么。请也提出建议。这是删节的代码:

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;

2 个答案:

答案 0 :(得分:1)

您需要传递for (var i = 0; i < 10; i += 1) { Action action = null; action = () => { actions.Remove(action); }; actions.Add(action); } Parallel.Invoke(actions.ToArray()); 一个将状态映射到道具的函数

connect

答案 1 :(得分:1)

您可能正在寻找作为道具传递的theme对象。 Material-UI使用上下文api,而不是redux。

  

withTheme()(Component)=>组件

     

提供主题对象作为输入组件的属性。