question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

local state for a select box

See original GitHub issue

There was a lot of discussion regarding sub-components in #2 and #73 already.

I was wondering how should one go about creating a reusable select box. There is a lot of state involved that does not necessary need to be stored in the root model:

  • filteredSuggestions - Filtered suggestion displayed in the dropdown menu
  • open - Is the dropdown menu open?
  • value - Current value of the select input box

In React, I created two components StatefulSelect and Select, the first maintaining it’s local state and the latter a stateless functional component representing it’s visual appearance.

const Select = () => { /* ... */ }

class StatefulSelect extends Component {
  constructor (props) {
    super(props)

    this.state = {
      value: '',
      open: false,
      filteredSuggestions: props.suggestions,
      selected: null
    }
  }

  // ... state update methods ...

  render () {
    return <Select open={this.state.open} />
  }
}

So in hyperapp there is no concept of local state, right? I need to attach the <Select /> state directly to the root model. Wouldn’t that be a use case for nested app()'s? And if not, I would love to see an implementation of a select box in hyperapp

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

4reactions
zacenocommented, Jun 22, 2017

@jbucaran 😆 indeed it is. Not saying anyone should do this. Just that you could 😉

2reactions
jorgebucarancommented, Jun 22, 2017

@zaceno This is dark magic!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Bind State with Select Option (Combo Box) on REACT ...
How To Bind State with Select Option (Combo Box ) on REACT.Hey guys!! if you learn something new or my video helps with...
Read more >
Passing value to state using react-select - Stack Overflow
I started using react-select to create a dropdown on a form and now I'm trying to pass the value of the option selected....
Read more >
How to change a select's options based on another dropdown ...
Create a local variable say type that will hold any of the array based on the ... "selected" here is state variable which...
Read more >
How To Create Searchable, Async Dropdowns with React ...
React Select is a highly configurable select menu library for React that features dynamic search and filter. It also supports async option ......
Read more >
How to Get Selected Value from a Mapped Select Input in React
Setting the Default Value Using State ... To select a default option in React, the selected attribute is used in the option element....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found