user2468312
user2468312

Reputation: 371

How to pass value to the react nativ webview body

I want to pass a value from react-native to webview

<WebView
  source={{
    uri: 'https://accountant.aqilz.com/add-new-submit-form.php',
    method: 'POST',
    body: 'cat=cat',
  }}
/>

Instead of hardcoded value cat=cat in the above code, I need to pass value from myId.

const myId = this.props.route.params.email;
<WebView
  source={{
    uri: 'abcd.com/add-new-submit-form.php',
    method: 'POST',
    body: 'cat=???',
  }}
/>

I want to pass the value from the const to the webview body. By doing this I can able to retrieve the login user email id.

Upvotes: 0

Views: 455

Answers (1)

bas
bas

Reputation: 15462

You can use template literals:

const myId = this.props.route.params.email;
<WebView
  source={{
    uri: 'abcd.com/add-new-submit-form.php',
    method: 'POST',
    body: `cat=${myId}`,
  }}
/>

You can also use standard string concatenation:

// ...
body: "cat=" + myId,
// ...

Upvotes: 2

Related Questions