Closed surahe closed 4 years ago
Environment React: 16.9 mobx-react-lite:1.5.2 React Developer Tools:4.4.0
I use useState in a component but it can't get the value while I create or update the state, it can only return Observer.
useState
How can I get the value while I use hooks and mobx-react-lite?
export const TodoAdd: React.FC = observer(() => { const [todoVal, setTodoVal] = useState('') const todoStore = useTodoStore() function handleEnterChange(evt: FormEvent<HTMLInputElement>) { setTodoVal(evt.currentTarget.value) } function handleEnterInput(evt: KeyboardEvent<HTMLInputElement>) { if (todoVal === '') { return } if (evt.keyCode === 13) { todoStore.addNewTodo(todoVal) setTodoVal('') } } return ( <div> <input value={todoVal} type="text" className="add" placeholder="Enter to add new todo" onChange={handleEnterChange} onKeyUp={handleEnterInput} /> </div> ) })
Try to look under .track in there. It's not very nice, that's true, but we are not aware of a better way right now.
.track
I get it, thx
Environment React: 16.9 mobx-react-lite:1.5.2 React Developer Tools:4.4.0
I use
useState
in a component but it can't get the value while I create or update the state, it can only return Observer.How can I get the value while I use hooks and mobx-react-lite?