1
我已經創建瞭如下的內部回調函數。如何使我的內部回調函數響應mobx狀態更改?
render() {
const profiles = this
.props
.store
.profiles;
const renderCell = (rowIndex: number) => {
console.log('rendering...');
return <Cell>{profiles[rowIndex].alias}</Cell>;
};
return (
<div className="profileList">
<Table
allowMultipleSelection={false}
numRows={this.props.store.profiles.size}
isRowHeaderShown={false}
selectionModes={SelectionModes.ROWS_AND_CELLS}
isColumnResizable={false}
isRowResizable={false}
defaultColumnWidth={1024}
onSelection={(region) => this.onSelection(region)}
>
<Column name="Connection Profiles" renderCell={renderCell.bind(this)}/>
</Table>
</div>
);
}
從上面的代碼中,你可以看到,有是render()
函數內部創建了一個renderCell
功能。當我更新mbox狀態profile.alias
時,此功能不會被觸發。如果我直接將profile.alias
置於render()
方法下,它可以正常工作。如何讓我的renderCell
響應狀態更改?
'observer(..)'返回與以前相同的反應組件嗎?完成更改後,我的組件根本不工作。我收到了一個錯誤異常:'警告:有些東西直接調用React組件。改用工廠或JSX。 ' –
您應該將它用作JSX組件調用語法: ' } />' 或者您可以使用'React.createFactory(component) '如果您不想使用JSX語法,則使用React文檔編寫的語法:[link](https://facebook.github.io/react/warnings/legacy-factories.html) –
AmitBu