2022-04-25

How to fix error (cant access lexical declaration Array before initialization ) in react.js?

I set the array in onchange method and I see it in the console with console.log("array =",array) with all elemets but when I want to delete the duplicate element with Array.from(new Set(array)) method in the update method , I find error in the console ( cant access lexical declaration Array before initialization ) !

const [array, setArray] = useState([]); 

const update = (e) =>{ 

  e.preventDefault();  console.log("array =",array);  // = [ 1,  1, 2, 2, 51, 51 ] 
  
  if( array !==undefined){ 
  
    const Array = Array.from(new Set(array));    // error   } }
    
    setarticlesolde((pre) => {      
 
      setArray((pre) => [pre.articleId]);
      return  [... pre];
    })


No comments:

Post a Comment