Skip to content

Instantly share code, notes, and snippets.

View cyrilf's full-sized avatar
🌱
what's up!

cyril cyrilf

🌱
what's up!
View GitHub Profile
@cyrilf
cyrilf / flattenArray.js
Created October 18, 2018 09:57
React util function to find and replace string with links in a label
const flattenArray = (arr) => arr.reduce((result, value) => result.concat(value), [])
@cyrilf
cyrilf / generatePassword.js
Created October 18, 2018 14:11
Simple password generator in JS
// Add IE11 support
const crypto = window.crypto || window.msCrypto
const generatePassword = (length = 10) => {
const buffer = new Uint8Array(12)
crypto.getRandomValues(buffer)
return btoa(String.fromCharCode.apply(null, buffer)).substr(0, length)
}
export default generatePassword
@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`.