Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Last active May 24, 2020 12:41
Show Gist options
  • Select an option

  • Save vanaf1979/ac27247dfe47cae3b17a6b35046fb0e9 to your computer and use it in GitHub Desktop.

Select an option

Save vanaf1979/ac27247dfe47cae3b17a6b35046fb0e9 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() {
// ...
useEffect(() => {
Axios.get("https://example.com/wp-json/wp/v2/posts", {
params: { page: page }
}).then(response => {
setNumberofpage(response.headers["x-wp-totalpages"]);
setPosts(response.data);
});
}, [page, setPosts]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment