Skip to content

Instantly share code, notes, and snippets.

@jmlavoier
Last active December 20, 2017 19:42
Show Gist options
  • Save jmlavoier/be6d2e7d61dfc1f1ea874061c948c416 to your computer and use it in GitHub Desktop.
Save jmlavoier/be6d2e7d61dfc1f1ea874061c948c416 to your computer and use it in GitHub Desktop.
This is a Input field to reuse.
// InputField.js
const onHandleChange = (validate, onChange) => event => {
const { value } = event.target;
const isValid = validate(value);
onChange(value, isValid);
}
const getStyle = isValid => ({
border: isValid ? '' : '1px solid red',
});
export const InputField = ({
value,
name,
type,
isValid,
validate,
onChange,
}) => (
<div>
<input
styles={getStyle(isValid)}
type={type}
name={name}
value={value}
onChange={onHandleChange(validate, onChange)}
/>
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment