Skip to content

Instantly share code, notes, and snippets.

@DreySkee
DreySkee / package.json
Created January 30, 2017 23:55
1 - Wordpress API + ReactJS
{
"name": "wp-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"alt": "^0.18.6",
"axios": "^0.15.3",
"lodash": "^4.17.4",
"react": "^15.4.2",
@DreySkee
DreySkee / index.html
Created January 30, 2017 23:57
2 - Wordpress API + ReactJS
<!DOCTYPE html>
<html>
<head>
<title>WP API</title>
</head>
<body>
<div id="app"></div> <!-- This div will be holding the app -->
<script src="bundle.js"></script> <!-- This is the main JS file that gets bundled by webpack -->
</body>
</html>
@DreySkee
DreySkee / webpack.config.js
Last active February 5, 2017 18:01
3 - Wordpress API + ReactJS
var webpack = require('webpack');
var path = require('path');
module.exports = {
devtool: 'inline-source-map', // This will show line numbers where errors are accured in the terminal
devServer: {
historyApiFallback: true, // This will make the server understand "/some-link" routs instead of "/#/some-link"
},
entry: [
'webpack-dev-server/client?http://127.0.0.1:8080/', // Specify the local server port
@DreySkee
DreySkee / index.js
Last active January 31, 2017 00:06
4 - Wordpress API + ReactJS
import React from 'react';
import {render} from 'react-dom';
import App from './components/App.js';
import Home from './components/Home.js';
import {
browserHistory,
IndexRoute,
Redirect,
Route,
@DreySkee
DreySkee / App.js
Created January 31, 2017 00:09
5 - Wordpress API + ReactJS
import React from 'react';
export default class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
@DreySkee
DreySkee / Home.js
Created January 31, 2017 00:11
6 - Wordpress API + ReactJS
import React from 'react';
class Home extends React.Component {
render() {
return (
<div>
<h1>Hello World</h1>
</div>
);
@DreySkee
DreySkee / Alt.js
Created January 31, 2017 00:12
7 - Wordpress API + ReactJS
import Alt from 'alt';
const alt = new Alt();
export default alt;
@DreySkee
DreySkee / DataActions.js
Last active February 18, 2020 10:27
8 - Wordpress API + ReactJS
import axios from 'axios';
import alt from './../alt/alt.js';
class DataActions {
constructor() {
const appUrl = 'http://wordpress-installation-example-url.com'; // Replace this with your WP installation url
this.pagesEndPoint = `${appUrl}/wp-json/wp/v2/pages`; // Endpoint for getting Wordpress Pages
this.postsEndPoint = `${appUrl}/wp-json/wp/v2/posts`; // Endpoint for getting Wordpress Posts
@DreySkee
DreySkee / DataStore.js
Last active January 31, 2017 00:23
9 - Wordpress API + ReactJS
import alt from './../alt/alt.js';
import DataActions from './../actions/DataActions.js';
class DataStore {
constructor() {
this.data = {};
this.bindListeners({
// Listen to the getSuccess() in DataActions.js
handleSuccess: DataActions.GET_SUCCESS
@DreySkee
DreySkee / index.js
Last active January 31, 2017 00:28
10 - Wordpress API + ReactJS
import React from 'react';
import {render} from 'react-dom';
import App from './components/App.js';
import Home from './components/Home.js';
import DataActions from './actions/DataActions.js';
import {
browserHistory,
IndexRoute,
Redirect,