0

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

2 Answers 2

2

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 <>...</>;
};
Sign up to request clarification or add additional context in comments.

Comments

0

Define handleChange function like this

 const handleChange = () => {
    return "Hello World!";
 };

Or

function handleChange(){
    return "Hello World!";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.