mobxjs / mobx-react-lite

Lightweight React bindings for MobX based on React 16.8 and Hooks
https://mobx.js.org/react-integration.html
MIT License
2.13k stars 90 forks source link

how can I get the hooks value by React developer Tools #251

Closed surahe closed 4 years ago

surahe commented 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.

How can I get the value while I use hooks and mobx-react-lite?

image

image

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>
  )
})
danielkcz commented 4 years ago

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.

surahe commented 4 years ago

I get it, thx

image

image