In my code i want to make when i select on radio button then click submit button then url is open this is fine right now.
But i want to make when i select on radio button and click on submit button then url is open with id fetch
and id is fetched in api on the basis of row select.
my full code is here plz check https://codesandbox.io/s/react-example-forked-hvisq?file=/index.js
i want to make when i select row and click on submit button then this type url is open http://commondatastorage.googleapis.com/codeskulptor-assets/space%20station.png/id/1 like that on another row when i select row and click on button then this type url is open http://commondatastorage.googleapis.com/codeskulptor-assets/space%20station.png/id/2.
but right now its simply url open without fetch id on the basis of select http://commondatastorage.googleapis.com/codeskulptor-assets/space%20station.png.
How can we do that.any idea on that
my code https://codesandbox.io/s/react-example-forked-hvisq?file=/index.js
handleClick = () => {
console.log(this.state.selectedId);
const apiUrl = "https://mocki.io/v1/b512f8b8-64ab-46e4-9e0c-9db538a0ad9e";
if (this.state.selectedId) {
console.log(this.state.selectedId);
fetch(apiUrl)
.then((response) => response.json())
.then((data) => {
this.setState({ data: data });
console.log("This is your data", data);
switch (this.state.selectedId) {
case "1":
window.open(
"http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png",
"_blank"
);
break;
case "2":
window.open(
"http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png",
"_blank"
);
break;
default:
break;
}
});
} else {
alert("Data not fetched!");
}
};
anybody help me out its very thankful.
url is open with id fetch?datais an array of objects, You want to pick theurlof the object in thedataarray where theidmatchesthis.state.selectedId.?