Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Last active May 24, 2020 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanaf1979/5d63a0f40a69a5e85a9c25c7e431c1ff to your computer and use it in GitHub Desktop.
Save vanaf1979/5d63a0f40a69a5e85a9c25c7e431c1ff to your computer and use it in GitHub Desktop.
Basic post navigation with React and the Wp Rest Api https://since1979.dev/basic-post-navigation-with-react-and-the-wp-rest-api/
import React, { useState, useEffect } from "react";
import Axios from "axios";
export default function App() {
// ...
return (
<div className="posts-app__wrapper">
<h1>Navigate Wp Rest Api Posts</h1>
<div className="posts-app__post-list">
{posts && posts.length && posts.map((post, index) => {
return (
<div key={post.id} className="posts-app__post">
<h2>{post.title.rendered}</h2>
<div dangerouslySetInnerHTML={{ __html: post.excerpt.rendered }} />
<a href={post.link} target="_blank">Read post</a>
</div>
);
})}
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment