2

我似乎无法理解有关如何将道具从视图传递到 redux 商店的文档。

注册.jsx

import configureStore from '../store/configureStore';

ReactOnRails.registerStore({
  configureStore,
});

// This is how react_on_rails can see the HelloWorld in the browser.   
[...]

意见:

<%= redux_store('configureStore', props: { profile: current_user.profile }) %>
<%= react_component 'NewProjectApp' %>

我现在迷路了。我认为在我的反应组件中我可以做到{props.profile}

我的应用程序将有多个组件连接一个商店。我是否需要创建一个 reducer 才能访问 profile 道具?

减速器:

[...]
const profile = (profile) => {
  console.log(profile)
  return " "
};

// exporting the combined reducers
// shorten:
// combineReducers({ profile });

[...]

奇怪的部分,在我的控制台中,我看到undefined了两次,然后是第三次。我看到了配置文件对象。嗯?HelloWorlApp我仍在通过更改在 Rails 上做出反应的默认示例来学习 redux 的工作原理。

4

0 回答 0