Skip to content

Instantly share code, notes, and snippets.

View fsartoris's full-sized avatar

Federico fsartoris

  • Argentina
View GitHub Profile
@cyrilf
cyrilf / react-select-event.jsx
Created August 30, 2018 15:45
Solution to receive an event with react-select onChange method
// Issue: `react-select` `onChange` method doesn't return a proper event
//
// Solution used:
//
// The main idea is to have an hidden `select` that will trigger a real event
// When `ReactSelect` triggers it's `onChange` we set the state with the `selectedOptions`
// these `selectedOptions` will be what populate our hidden select.
// Using the callback from `setState` (it ensures that the new values are already into our hidden select),
// we then create a change event and dispatch it into our hidden select.
// This will cause the `onChange` from this select to be triggered with a proper `event`.