我正试图将props对象从App.js传递到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);
}
};
...
试图接收道具的子组件抛出未定义的错误。我不能正确导出道具吗?