local state for a select box
See original GitHub issueThere 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 menuopen
- 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:
- Created 7 years ago
- Reactions:2
- Comments:15 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jbucaran 😆 indeed it is. Not saying anyone should do this. Just that you could 😉
@zaceno This is dark magic!