Skip to content

Instantly share code, notes, and snippets.

@toto011
Last active November 27, 2018 09:19
Show Gist options
  • Save toto011/628241727d24b955d217805c8c65b826 to your computer and use it in GitHub Desktop.
Save toto011/628241727d24b955d217805c8c65b826 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { render } from "react-dom";
import cheerio from "cheerio";
import renderHTML from "react-render-html";
import "./index.css"
class App extends Component {
state = {
data: [],
logos: []
};
componentDidMount() {
this.getDataFromApi();
}
getDataFromApi = () => {
fetch("https://facebook.github.io/react-native/")
.then(response => response.text())
.then(data => {
const $ = cheerio.load(data);
this.setState({ logos: $(".logos").html() });
})
.catch(error => {
this.setState({ error: error });
});
}
render () {
const thisLogosWithImages = String(this.state.logos).replace(new RegExp('/react-native', 'g'), 'https://facebook.github.io/react-native');
console.log(thisLogosWithImages);
return <div className="App">{renderHTML(String(thisLogosWithImages))}</div>;
}
}
render(<App />, document.getElementById("root"));
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment