& The Chamber of
Single Page Apps
A client needs functionality too complex/custom
for an existing plugin or theme
BUT, you still want all the great
functionality of WordPress
Within a WordPress theme,
show custom content
within a Single Page App
https://github.com/lasergoat/wordcamp-spa
functions.php
Text
(CPT)
(ACF)
Older versions of JSON-API don't include ACF meta data when you request a custom post
functions.php
GET: /api/get_posts/?post_type=patronus
This is the resource which your
javascript frontend will Fetch
If complex joins, searching, or other advanced functionality is required,
Custom post types are great for flat data with minimal functionality
use Laravel instead of CPTs
functions.php
<div id="app"></div>
<script src="path/to/bundle.js">
</script>
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
render() {
// poop out the app
}
}
ReactDOM.render(<App />, document.getElementById('app'));
What are thooooose?
function mapPatronus(patronus) {
return {
id: patronus.id,
visible: true,
...patronus.acf
};
}
componentDidMount() {
fetch('/api/get_posts/?post_type=patronus&count=99')
.then((res) => res.json())
.then((res) => {
this.setState({
patronuses: res.posts.map(mapPatronus)
});
});
}