Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6314

How to optimize App in ReactJS on re-renders

$
0
0

I have to optimize this App here, How can I implement or pass onDelete to Child so I don't have new function on each re-render? (I am not allowed to change the child component)

function App() {  const [names, setNames] = React.useState(["iamfirst", "methesecond"]);  const onDelete = useCallback( (index:number) => {    setNames((prev) => prev.filter((_, i) => i !== index));  }, []);  return (<div>      {names.map((name, index) => (<Child          key={index}          name={name}          onChange={onNameChange}          onDelete={()=>onDelete(index)}        />      ))}</div>  );}

Viewing all articles
Browse latest Browse all 6314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>