I am getting error "Cannot read property 'fname' of undefined"

html dont have any code just importing this code

  import React, { useState } from "react";
  function App() {
  const [fullname, setFullName]= useState({
  fname: "",
  lname: ""


  function Name(event){
    const newvalue = event.target.value;
    const newname = event.target.name;

    setFullName(prevValue => {
      if(newname === "fname"){
        return {
          fname: newvalue,
          lname: prevValue.lname          
      }else if(newname === "lname"){
        return {
          fname: prevValue.fname,
          lname: newvalue

  return (
    <div className="container">
      <h1>Hello </h1>
        // value={fullname.fname}
        placeholder="First Name" />
        // value={fullname.lname}
        placeholder="Last Name" />
export default App;

When I am console.log fullname the it shows fname and lname but when i use it as fullname.fname or fullname.lname it sows error. I have defined fname and lname in useState what’s the problem I cant find it. I have tried console.log at multiple places it does not work

189 thoughts on “I am getting error "Cannot read property 'fname' of undefined"”

  1. Pingback: is stromectol
  2. Pingback: priligy hcl
  3. Pingback: uti stromectol 6mg
  4. Pingback: ivermect 125 mg

Leave a Comment