reactjs - React.js:将道具传递给 MobX 商店
问题描述
我正在尝试将 App.js 中的 props 对象传递到 MobX 商店,如下所示:
//ui_store.js
import {message_construction_logic, App} from "../App";
export class UiStore {
starting_array = [<ChoosePostType ui_store={ui_store} go_to_anchor_link={this.props.go_to_anchor_link} />];
...
在 App.js 中,我设置了要作为道具传递的函数,如下所示:
class App extends Component {
constructor(props) {
super(props);
this.go_to_anchor_link = this.go_to_anchor_link.bind(this)
};
// METHODS ===========================================
go_to_anchor_link = (anchor_id) => {
const scroll_target = document.getElementById(anchor_id);
console.log('anchor_id', anchor_id); // returns "question_leads", which is correct
if (scroll_target) {
console.log('scroll_target', scroll_target);
smoothScroll(scroll_target);
}
};
...
尝试接收道具的子组件抛出未定义的错误。我没有正确导出道具吗?
解决方案
推荐阅读
- c# - 无法使用 MVVM 设计模式用 Sql server 列填充 ComboBox
- javascript - 如何在 wocommerce 结帐时显示运输选项
- laravel - Laravel after_or_equal 某些日期有问题
- javascript - 反应传单 - MapContainer 仅获取父 useState 的初始值
- batch-file - 百分比编码保留字符
- php - 如果值存在,则在编辑页面中选中复选框
- php - 我如何用相同的获取请求 php 卷曲下一页
- python - 更改数据框中多列类别的最佳方法
- javascript - 如何在javascript中检索单引号单词形式的句子?
- python - 如何将排列的输出放入列表中