DEV Community

Rita
Rita

Posted on

How reduce code in React

How can reduce code in React , don’t writing it several time?
function App(){
const [name1,setName1]=useState('');
const [name2,setName2]=useState('');
var arr2=['A','D'];
function naM1(){
setName1(arr2[0]);
}
function naM2(){
setName2(arr2[1]);
}
return(

{arr2[0]}

{arr2[1]}

---------ADDED ITEMS-------------

{name1}

{name2}

);
}

Top comments (1)

Collapse
 
boiledsteak profile image
boiledsteak

try use the markdown code feature. It's hard to read what you've written