Skip to content

Use ListBox from @headlessui/react with Mobx? #2729

Discussion options

You must be logged in to vote

Alright I solved it. Removed the local hook state & just used the MobX state. Also, had 1 minor issue. I was setting the value as uppercase in the store when the store originally had lowercase values. The uppercase values were only for display in the UI.

Here's the modified code that works:

App.tsx

<Select
  label="Shape"
  options={shapes}
  value={shapes.filter({ name }) => name.toLowerCase() === frameItStore.trafficSignal.shape)[0]}
  onChange={(value) => {
    const shape = value.toLowerCase() as TrafficSignalShape
    frameItStore.updateTrafficSignal({ shape })
  }}
/>

Select.tsx

import * as React from 'react'
import { Listbox, Transition } from '@headlessui/react'
import clsx from '…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@deadcoder0904
Comment options

@deadcoder0904
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by deadcoder0904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants