Answer the question
In order to leave comments, you need to log in
What are the three best ways to reduce code in react?
I have this code
import React,{useState,useEffect} from "react";
import ReactDOM from "react-dom";
function App() {
const [listImg, setLis] = useState([]);
const [Indx, setIndx] = useState(0);
const [resErrX, setErrorX] = useState("");
useEffect(() => {
(async () => {
try {
const Res = await fetch(......);
const Product = await Res.json();
setLis(
Product.x
.map((value, index) => ({
key: `${value}`,
z:`${index}`,
y: `${value}`,
onClick: () => {
setIndx(index);
}
}))
);
} catch (error) {
setErrorX(error.message);
}
})();
}, []);
return (
<div className="App">
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
({
key: `${value}`,
z:`${index}`,
y: `${value}`,
onClick: () => {
setIndx(index);
})
const DDX = {
key: `${value}`,
z:`${index}`,
y: `${value}`,
onClick: () => {
setIndx(index);
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question