Last active
May 24, 2020 13:14
-
-
Save vanaf1979/329abed564c2ba10eda29a53b399ac69 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, { useState, useEffect } from "react"; | |
import Axios from "axios"; | |
export default function App() { | |
const [post, setPost] = useState(null); | |
useEffect(() => { | |
Axios.get("https://since1979.dev/wp-json/wp/v2/posts/1601").then( | |
response => { | |
setPost(response.data); | |
} | |
); | |
}, [setPost]); | |
return ( | |
<div className="App"> | |
{post && ( | |
<div> | |
<h1>{post.title.rendered}</h1> | |
<div dangerouslySetInnerHTML={{ __html: post.excerpt.rendered }} /> | |
</div> | |
)} | |
</div> | |
); | |
} | |
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, { useState, useEffect } from "react"; | |
import Axios from "axios"; | |
import parse from "html-react-parser"; | |
export default function App() { | |
// ... | |
return ( | |
<div className="App"> | |
{post && ( | |
<div> | |
<h1>{post.title.rendered}</h1> | |
{parse(post.content.rendered)} | |
</div> | |
)} | |
</div> | |
); | |
} | |
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 from "react"; | |
import parse from "html-react-parser"; | |
import Gist from "super-react-gist"; | |
export default function WpApiContent(props) { | |
return parse(props.content, { | |
replace: (domNode) => { | |
if(domNode.name === "script" && domNode.attribs.src.indexOf("/gist.github.com/") ) { | |
return (<Gist url={domNode.attribs.src.replace(".js", "")} />) | |
} | |
} | |
}); | |
} | |
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, { useState, useEffect } from "react"; | |
import Axios from "axios"; | |
import WpApiContent from "./WpApiContent.js"; | |
export default function App() { | |
// ... | |
return ( | |
<div className="App"> | |
{post && ( | |
<div> | |
<h1>{post.title.rendered}</h1> | |
<WpApiContent content={post.content.rendered} /> | |
</div> | |
)} | |
</div> | |
); | |
} | |
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, { useState, useEffect } from "react"; | |
import Axios from "axios"; | |
import WpApiContent from "./WpApiContent.js"; | |
export default function App() { | |
const [post, setPost] = useState(null); | |
useEffect(() => { | |
Axios.get("https://since1979.dev/wp-json/wp/v2/posts/1601").then( | |
response => { | |
setPost(response.data); | |
} | |
); | |
}, [setPost]); | |
return ( | |
<div className="App"> | |
{post && ( | |
<div> | |
<h1>{post.title.rendered}</h1> | |
<WpApiContent content={post.content.rendered} /> | |
</div> | |
)} | |
</div> | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment