Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

TypeScript how to pickup values from and pass to an API method

$
0
0

I want to pickup values from html input and send them to const User api call.How do i pass values from <input value={UserValue} and pass them to User function((client) => client.create(UserValue

import React, { useState } from 'react';import FHIR from 'fhirclient';const CreateUser: React.FunctionComponent = () => {  const [UserValue, setTerm] = useState('');  const submitForm = (event: React.FormEvent<HTMLFormElement>) => {    // Preventing the page from reloading    event.preventDefault();    try {      const User = FHIR.oauth2.ready()       .then((client) => client.create(UserValue, {         headers: { prefer: 'return=representation' },          })        );      if (User) {        alert('Patient was created ID: '+ User);        console.log(User);      }    } catch (error) {      alert(error);    }  };  return (<div className="container"><form onSubmit={submitForm}><input          value={UserValue}          onChange={(e) => setTerm(e.target.value)}          type="text"          placeholder="Enter a user name"          className="input"        /><input          value={UserValue}          onChange={(e) => setTerm(e.target.value)}          type="text"          placeholder="Enter a email"          className="input"        /><input          value={UserValue}          onChange={(e) => setTerm(e.target.value)}          type="text"          placeholder="Enter a user name"          className="input"        /><input          value={UserValue}          onChange={(e) => setTerm(e.target.value)}          type="text"          placeholder="Enter a password"          className="input"        /><button type="submit" className="btn">          Submit</button></form></div>  );};export default CreateUser;

stackblitz link here to run the code


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>