I am looking to identify how the body looks for following request.
This is existing code which sends a post call to another client and also redirects to that client.
When normally making a post call, I am expecting the body to look something like this.
{
someKey: 'some value'
}
But in this case, only the value is being set. What is the key here?
//Just from a normal js file.
export const postData = (myRef, token, link) => {
// question is on this line. Just setting a value. What is the key for the post body?
myRef.current.children[0].value = token;
myRef.current.action = link;
myRef.current.submit();
};
This is the component where on click we call above function where we post and redirect to link.
const AComponent = () => {
const myRef = React.useRef();
const submit = () => {
postData(myRef, 'some long token', 'www.google.com');
};
return (
{/* Button is just another component that acts like a normal html button with some styling*/}
<Button onClick={submit}>
Click Me!
</Button>
);
};
export default AComponent;
You can do this by creating an Object & then assigning {key: value} pair to it.
const obj = new Object();
obj['some key'] = "some value";
Maybe this is helpful to you, if still, this doesn't answer your question, you can ping me for further reference.