M
M
Matvey Ptushkin2020-07-08 00:02:16
JavaScript
Matvey Ptushkin, 2020-07-08 00:02:16

How to insert text into div from JSON so that html elements are read and not displayed as text?

5f04e21977df4105394392.png
5f04e2c5234c2929481323.png

import React from "react";
import "./About.css";

class About extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      leftTitle: "",
      rightTitle: "",
      col: "",
      leftP1: "",
      leftP2: "",
    };
  }

  componentDidMount() {
    fetch(
      "https://gist.githubusercontent.com/alexandrov-va/7f353ca822d074d7ce22d3af3d13696f/raw/0907091de6fedf6153cdb718f32a4215dc2c53cf/page.json"
    )
      .then((response) => response.json())
      .then((data) => {
        console.log(data);
        this.setState({
          leftTitle: data.components[1].metadata.components[0].metadata.title,
        });
        this.setState({
          col: data.components[1].metadata.components[0].col,
        });
        this.setState({
          leftP1: data.components[1].metadata.components[0].metadata.text,
        });
        this.setState({
          rightTitle: data.components[1].metadata.components[1].metadata.title,
        });
      })
      .catch((error) => console.error(error));
  }
  render() {
    return (
      <div>
        <div className="row">
          <div className={"col-" + this.state.col}>
            <h1>{this.state.leftTitle}</h1>
            <p>{this.state.leftP1}</p>
          </div>
          <div className={"col-" + this.state.col}>
            <h1>{this.state.rightTitle}</h1>
            <p>{this.state.leftP1}</p>
          </div>
        </div>
      </div>
    );
  }
}

export default About;

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