Reputation: 101
I am new to react, I am trying to call an function , Here is my code:
import React,{useState} from "react";
import { Link } from "react-router-dom";
import axios from "axios"
import { ToastContainer, toast } from 'react-toastify';
const Register = prop => {
const [username, setusername] = useState([]);
handleChange = () => {
return "Hello World!";
}
return (
<>
<Form role="form">
<FormGroup className="has-success">
<InputGroup className="input-group-alternative mb-3">
<InputGroupAddon addonType="prepend">
<InputGroupText>
<i className="ni ni-hat-3" />
</InputGroupText>
</InputGroupAddon>
<Input
className="form-control-alternative is-valid"
placeholder="User Name"
type="text"
onChange={handleChange}
id="input-username"
/>
</InputGroup>
</FormGroup>"text-center">
<Button className="mt-4" color="primary" type="button">
Create account
</Button>
</div>
</Form>
</>
);
};
export default Register;
i am trying to setstates on change function , but i am facing an error "handleChange not defined"
Thanks in advance
Upvotes: 0
Views: 63
Reputation: 1663
Define handleChange function like this
const handleChange = () => {
return "Hello World!";
};
Or
function handleChange(){
return "Hello World!";
}
Upvotes: 0
Reputation: 53874
You need to define the function, as for now you assigning the function to a variable named handleChange
, which does not exists in current scope.
const Register = (prop) => {
// add const beforehand
const handleChange = () => {...};
return <>...</>;
};
Upvotes: 2