我嘗試訪問組件中的一些參考。但是我在控制檯中有這個錯誤。 withRouter.js:44 Warning: Stateless function components cannot be given refs (See ref "pseudo" in FormInputText created by RegisterForm). Attempts to access this ref will fail.
無狀態功能組件無法提供參考
這裏是我的組件:
class RegisterForm extends React.Component {
render() {
return (
<form action="">
<FormInputText ref="pseudo" type="text" defaultValue="pseudo"/>
<input type="button" onClick={()=>console.log(this.refs);} value="REGISTER"/>
</form>
);
}
}
另外,當我點擊我的控制檯得到Object {pseudo: null}
按鈕。我期望一個對象,而不是null
。
我不知道爲什麼這不起作用。請注意,我的反應樹使用mobx-react
。
的[陣營無狀態組件this.refs..value?]可能的複製(http://stackoverflow.com/questions/37266411/react-stateless-component-this-refs-value) –