Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I want to rerender a image with the new value of the useState of the component that its in a child component passing the props Im adding the code from both component

What I have tried:

import DefaultColor from './DefaultColor';
function App() {  
colorData = [{color: "black",background: "black"},{color: "mint", background:"#2CB695"}];
const afterClick = (e) =>{
    
       setBody(e.target.id)      
     }
  
const [body, setBody] = useState("Black")
   
  return (
  <>

  <div className="container">

     <DefaultColor props={body}/>

  </div>
        
      <div className="container-car">

      {ColorsData.map((color,background) =>{
            return(
              <div className="card-car">
                    <div className="box-car"
                      key={color.color + body}
                      id={color.color} 
                      onClick={afterClick}
                      style={{background : color.background}}>
                    </div>
                    <p>{color.color}</p>
             </div>  
                   )
           })}
        </div>
      </div>
</>
```

```code
function DefaultColor(props) {
  return (
    <> 
       <div className="default-container">        
           <img src="./images/abc-{body}.png"/>       
       </div>
    </>
  )
}

export default DefaultColor
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900