I have an input field and when the button is clicked I would like to store the input to a variable and output it to console. Here is my code:
function InputDD() {
const [inputValue, setInputValue] = useState('');
const onChangeHandler = event => {
setInputValue(event.target.value);
};
//console.log(inputValue) <- Not working
return(
<div>
<Form>
<FormGroup>
<Input type="lk" name="inputK" id="inputK" className="ink" value={inputValue} onChange={onChangeHandler} />
</FormGroup>
<Button size="sm" className="nextbtn">Lets roll</Button>
<!--Not working -> <Button size="sm" className="nextbtn" onClick={console.log(inputValue)}>Lets roll</Button>-->
</Form>
</div>
)
}
export default InputDD;
Currently, whenever an input is entered, the keys are output in console like in this image:
I do not want this and only want the whole text that is input stored to a variable and printed to console when the button is clicked.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment