V
V
Vadim Yagofarov2020-07-16 18:01:55
JavaScript
Vadim Yagofarov, 2020-07-16 18:01:55

How to save the result of a get request and pass it to ReactDOM.render for rendering?

Here is the code

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import Form from "@rjsf/core";
import axios from 'axios';

  //Form = JSONSchemaForm.default;

  const onSubmit = ({ formData }) => console.log("Data submitted: ", formData);

  state = {
    scheme: []
  }
  
  const scheme =  axios.get(`http://localhost/lk-ssl/hs/json/new_student`.json)
        .then(res => {
          const schema= res.data;
          console.log(schema);
          this.setState({ scheme});
          return scheme;
      })
  
    
  
  
  ReactDOM.render((
    <Form schema={schema}
      onSubmit={onSubmit}/>),
      document.getElementById('app')
  );

How to save the result of a get request and pass it to ReactDOM.render for rendering? Now exit error
Failed to compile
./src/index.js
  Line 13:3:   'state' is not defined   no-undef
  Line 29:19:  'schema' is not defined  no-undef

Search for the keywords to learn more about each error.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question