Skip to content

Instantly share code, notes, and snippets.

@HelveticaScenario
Last active June 17, 2017 01:10
Show Gist options
  • Save HelveticaScenario/c694c4b3563348a34e728ab3a8eda465 to your computer and use it in GitHub Desktop.
Save HelveticaScenario/c694c4b3563348a34e728ab3a8eda465 to your computer and use it in GitHub Desktop.
a typesafe curried react input handler using ramda
import * as R from 'ramda'
const _handleChangeCurried = function<S, P>() {
return <K extends keyof S>() => {
return R.curry<
React.Component<any, S>,
K,
React.FormEvent<HTMLInputElement>,
void
>((self, key, e) =>
self.setState(R.assoc(key, e.currentTarget.value, self.state))
)
}
}
export const handleChangeCurried = <S, P>() => _handleChangeCurried<S, P>()()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment