Fetch

axios.get('https://example.com')
.then(response => {console.log(response.data)})
.catch(error => {n(error)})
--------------_-----________----____
Axios.get 

axios.get('http://localhost:5000/api/data')
  .then(response => {
    document.getElementById('data').innerText = JSON.stringify(response.data, null, 2);
  })
  .catch(error => {
    document.getElementById('data').innerText = 'Error loading data';
    console.error(error);
  });
-----------------------------------
 Js cheatsheet
Fetching
('https://getserver.com/api').then((res) => res.json()).then(function(data) { var value = data.values; const formatData = (temp) => { return temp.map(({ Id, value: {descr}}) => ({Id, descr})); }; var output = formatData(value); console.log(output) }).catch(e => { console.log("fetch fail: " + e);});

class MarkdownEditor extends React.Component {
  constructor(props) {
    super(props);
    this.md = new Remarkable();
    this.handleChange = this.handleChange.bind(this);
    this.state = { value: 'Hello, **world**!' };
  }

  handleChange(e) {
    this.setState({ value: e.target.value });
  }

  getRawMarkup() {
    return { __html: this.md.render(this.state.value) };
  }
--------------------------------- 
  Fetch jsx :
render() {
    return (
      <div className="MarkdownEditor">
        <h3>Input</h3>
        <label htmlFor="markdown-content">
          Enter some markdown
        </label>
        <textarea
          id="markdown-content"
          onChange={this.handleChange}
          defaultValue={this.state.value}
        />
        <h3>Output</h3>
        <div
          className="content"
          dangerouslySetInnerHTML={this.getRawMarkup()}
        />
      </div>
    );
  }
}

root.render(<MarkdownEditor />);

Comments

Popular posts from this blog

Petroleum