I'm new in react , node and express. I have make a front end called home.js. Inside home.js, i got a code to call API in node js using axios, and then the node js will return the result from query DB. How i can use the result in front end that is sent from node js. I have already put the response in const data, but i can't used it for the const list.
Here is code in Front End (Home.js)
axios.get("http://localhost:3001/process", {
}).then(function(response) {
const data = response;
}).catch(error => console.log(error))
const list = [
{
img: ava1,
Title: data[0].month,
bud: "Rp 8,2 M",
progress: <Progress percent={60} size="small" />,
member: (
<div className="avatar-group mt-2">
<Tooltip placement="bottom" title="Ryan Tompson">
<img className="tootip-img" src={team1} alt="" />
</Tooltip>
{/*<Tooltip placement="bottom" title="Romina Hadid">
<img className="tootip-img" src={team2} alt="" />
</Tooltip>
<Tooltip placement="bottom" title="Alexander Smith">
<img className="tootip-img" src={team3} alt="" />
</Tooltip>
<Tooltip placement="bottom" title="Jessica Doe">
<img className="tootip-img" src={team4} alt="" />
</Tooltip>*/}
</div>
),
},
{
img: ava2,
Title: data[1].month,
bud: "$2,5 M",
progress: <Progress percent={10} size="small" />,
member: (
<div className="avatar-group mt-2">
{/*} <Tooltip placement="bottom" title="Ryan Tompson">
<img className="tootip-img" src={team1} alt="" />
</Tooltip>*/}
<Tooltip placement="bottom" title="Romina Hadid">
<img className="tootip-img" src={team2} alt="" />
</Tooltip>
</div>
),
},
{
img: ava3,
Title: data[2].month,
bud: "Rp 12.5 M",
progress: <Progress percent={100} size="small" status="active" />,
member: (
<div className="avatar-group mt-2">
{/*<Tooltip placement="bottom" title="Ryan Tompson">
<img className="tootip-img" src={team1} alt="" />
</Tooltip>
<Tooltip placement="bottom" title="Romina Hadid">
<img className="tootip-img" src={team1} alt="" />
</Tooltip>*/}
<Tooltip placement="bottom" title="Alexander Smith">
<img className="tootip-img" src={team3} alt="" />
</Tooltip>
</div>
),
},
{
img: ava4,
Title: data[3].month,
bud: "Rp. 13,0 M",
progress: <Progress percent={100} size="small" status="active" />,
member: (
<div className="avatar-group mt-2">
{/*<Tooltip placement="bottom" title="Ryan Tompson">
<img className="tootip-img" src={team1} alt="" />
</Tooltip>
<Tooltip placement="bottom" title="Romina Hadid">
<img className="tootip-img" src={team2} alt="" />
</Tooltip>*/}
<Tooltip placement="bottom" title="Jessica Doe">
<img className="tootip-img" src={team4} alt="" />
</Tooltip>
</div>
),
},
{
img: ava5,
Title: data[4].month,
bud: "Rp. 8,9 M",
progress: <Progress percent={80} size="small" />,
member: (
<div className="avatar-group mt-2">
<Tooltip placement="bottom" title="Ryan Tompson">
<img className="tootip-img" src={team1} alt="" />
</Tooltip>
<Tooltip placement="bottom" title="Romina Hadid">
<img className="tootip-img" src={team2} alt="" />
</Tooltip>
<Tooltip placement="bottom" title="Alexander Smith">
<img className="tootip-img" src={team3} alt="" />
</Tooltip>
<Tooltip placement="bottom" title="Jessica Doe">
<img className="tootip-img" src={team4} alt="" />
</Tooltip>
</div>
),
},
{
img: ava6,
Title: data[5].month,
bud: "Rp. 15,3 M",
progress: (
<Progress
percent={100}
size="small"
status="active"
// status="exception"
//format={() => "Cancel"}
/>
),
member: (
<div className="avatar-group mt-2">
<Tooltip placement="bottom" title="Ryan Tompson">
<img className="tootip-img" src={team1} alt="" />
</Tooltip>
<Tooltip placement="bottom" title="Romina Hadid">
<img className="tootip-img" src={team2} alt="" />
</Tooltip>
</div>
),
},
];
Here is the code in back end (index.js)
app.get('/process/', function (req, res) {
db.query(
"select * from process order by id desc LIMIT 1 ",
[],
(err,result) => {
if(err) {
res.send({err:err});
}
if(result.length > 0) {
axios.get("http://localhost:3001/echart/"+result[0].id, {
}).then(function(response) {
const status = response.status;
}).catch(error => console.log(error))
//console.log(result[0].id);
}
else
{
res.send('None shall pass process');
}
}
)
});
app.get('/echart/:seq_no', function (req, res) {
const seq_no = req.params.seq_no;
db.query(
"SELECT * from sales1 where seq_no = ? ",
[seq_no],
(err,result,fields) => {
if(err) {
res.send({err:err});
}
if(result.length > 0) {
res.send(result.response);
console.log('yes');
}
else
{
res.status(400);
res.send('None shall pass echart');
}
}
)
});