My React app code keeps giving an error “Cannot read property 'fname' of undefined” and I don't understand why

Asked
Active3 hr before
Viewed126 times

3 Answers

errorpropertyreact
90%

I am a beginner in React, just started using hooks. Above code renders a form which is supposed to take the first name and the last name as an input, individually, and update it in the heading in real-time. But the moment I type something it throws and error: "× ←→1 of 7 errors on the page TypeError Cannot read property 'fname' of undefined", Why bother maintaining a road bike for summer and a mountain bike for winter rather than two complete sets of wheels (as with cars) on a cyclocross? ,Connect and share knowledge within a single location that is structured and easy to search.

Also your setFullname can be simplified

const [{
   fName,
   lLame
}, setFullname] = useState({
   fName: " ",
   lLame: " "
});

function handleChange({
   target: {
      name,
      value
   }
}) {
   setFullname(state => ({
      ...state,
      [name]: value
   }));
}
 <input
          onChange={handleChange}
          name="fName"
          value={fFame}
          placeholder="First Name"
        />
        <input
          onChange={handleChange}
          name="lName"
          placeholder="Last Name"
          value={lName}
        />
load more v
88%

Pretag
 Pretag team - issue, fix, solve, resolve
72%

Error message shown on console and it said;,// Uncaught TypeError: Cannot read property 'position' of undefined;, 16 Parameter 0 of constructor in required a bean of type 'java.lang.String' that could not be found

Here is source

// Constructing * The Solar *
var shape = new THREE.BufferGeometry();
shape.addAttribute('position', new THREE.Float32Attribute(6, 3));
// console shows problem is here but I can't find any
shape.addAttribute('textureOrder', new THREE.Int8Attribute(6, 1));

for (var i = 0; i < 6; i++) {
   shape.attribute.position.setXYZ(i, 0, 0, 0);
   shape.attribute.textureOrder.setX(i, i);
};

var d = new Date();

var mater = new THREE.ShaderMaterial({
   uniforms: {
      time: {
         type: 'f',
         value: d.getTime()
      },
      tsun_core: {
         type: 't',
         value: loadTexture('./sun_core.png')
      },
      tsun_innerglow: {
         type: 't',
         value: loadTexture('./sun_innerglow.png')
      },
      tsun_starlight: {
         type: 't',
         value: loadTexture('./sun_starlight.png')
      },
      tsun_outerglow: {
         type: 't',
         value: loadTexture('./sun_outerglow.png')
      },
      tsun_shortjetlight: {
         type: 't',
         value: loadTexture('./sun_shortjetlight.png')
      },
      tsun_longjetlight: {
         type: 't',
         value: loadTexture('./sun_longjetlight.png')
      }
   },
   vertexShader: document.getElementById('vs-sun').textContent,
   fragmentShader: document.getElementById('fs-sun').textContent
});
mater.depthTest = false;
mater.vertexColor = true;
mater.transparent = true;
mater.blending = THREE.AdditiveBlending;

sun = new THREE.ParticleSystem(shape, mater);
scene.add(sun);
load more v

Other "error-property" queries related to "My React app code keeps giving an error “Cannot read property 'fname' of undefined” and I don't understand why"