Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Last active April 15, 2024 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vanaf1979/4fca2b65c6cf08a83c2bfa7d3ef6459e to your computer and use it in GitHub Desktop.
Save vanaf1979/4fca2b65c6cf08a83c2bfa7d3ef6459e to your computer and use it in GitHub Desktop.
Fixing and Parsing WordPress Rest Api content in React. https://since1979.dev/fixing-and-parsing-wordpress-rest-api-content-in-react/
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/1627").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>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment