Last active
November 27, 2018 09:19
-
-
Save toto011/628241727d24b955d217805c8c65b826 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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