Set of hooks to manage your inputs.
yarn add react-use-inputs
# or
npm i react-use-inputs
import { useCheckbox } from 'react-use-inputs'
() => {
const checkbox = useCheckbox({ state: true });
return <input {...checkbox}>;
}
const checkbox = useCheckbox({ state: true });
const value = checkbox.checked;
const checkbox = useCheckbox({ state: true });
return (
<>
<input {...checkbox}>
<button type="button" onClick={checkbox.onChange}>Trigger</button>
</>
);
useCheckbox({
state: boolean;
disabled?: boolean = false;
id?: string;
name?: string;
})
import { useRadio, RadioGroup } from "react-use-inputs";
() => {
const radio = useRadio({ state: "B", name: "test" });
return (
<RadioGroup {...radio}>
<label htmlFor="A">A</label>
<input value="A" id="A" />
<label htmlFor="B">B</label>
<input value="B" id="B" />
</RadioGroup>
);
};
const radio = useRadio({ state: "B", name: "test" });
const value = radio.value;
const radio = useRadio({ state: "B", name: "test" });
return (
<>
<RadioGroup {...radio}>
<label htmlFor="A">A</label>
<input value="A" id="A" />
<label htmlFor="B">B</label>
<input value="B" id="B" />
</RadioGroup>
<button type="button" onClick={() => radio.onChange("B")}>
Reset value to "B"
</button>
</>
);
useRadio({
state: string;
name: string;
})
import { useSelect } from "react-use-inputs";
() => {
const select = useSelect({ state: "A" });
return (
<select {...select}>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
);
};
const select = useSelect({ state: "A" });
const value = select.value;
const select = useSelect({ state: "A" });
return (
<>
<select {...select}>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<button type="button" onClick={() => select.onChange("B")}>
Reset value to "B"
</button>
</>
);
useSelect({
state: string;
id?: string;
name?: string;
disabled?: boolean = false;
})
import { useTextInput } from "react-use-inputs";
() => {
const textInput = useTextInput({ state: "" });
return <input {...textInput} />;
};
const textInput = useTextInput({ state: "" });
const value = textInput.value;
const textInput = useTextInput({ state: "" });
return (
<>
<input {...textInput} />
<button type="button" onClick={() => textInput.onChange("")}>
Reset
</button>
</>
);
useTextInput({
state: string;
type?: string = 'text';
disabled?: boolean = false;
id?: string;
name?: string;
placeholder?: string;
})
MIT