So I've created a component that shoots off post requests with props that I provide.
Although I'm familiar with Async await I for some reason can't seem to get this to return the actual value of the fulfilled promise and instead just get pending.
I've tried wrapping with more functions as I understand the promise is not being resolved.
I feel like I'm missing something.
A sample of my code below
export default class PostController extends React.Component {
constructor(props) {
super(props)
}
Wrapper = (body) => {
try{
let x = this.Send(body);
return x;
console.log(x)
}catch(e){console.log(e)}
}
Send = async (body) => {
try{
let data = await this.Post(body);
return data;
}catch(e){console.warn(e)}
}
Post = async (body) => {
try{
const options = {
method: 'POST',
uri: 'XXXXXXXXXXXXXXXXXXXX',
body: body
}
const data = await rp(options);
return data;
}catch(e){console.warn(e)}
}
render(props) {
let jsonBody = JSON.stringify(this.props.data)
const returnData = this.Wrapper(jsonBody)
console.log(returnData)
return(
<div>
{(!this.props.data.pw) ? 'Retrieved Password: ' + returnData.message : 'Generated PassWord!:' + returnData.message }
</div>
)
}
}
rp(options)
is, and why it awaits something?... – Marou