Skip to content

Instantly share code, notes, and snippets.

@Colour-Full
Colour-Full / index.html
Last active March 25, 2018 17:04
Simple Router Example Index HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>React Router Example</title>
</head>
<body>
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
// We will need to import this from redux to create our store and make use of the thunk
import { createStore, applyMiddleware } from 'redux';
// Dont forget to import redux thunk
import thunk from 'redux-thunk';
// Getting our combined reducers
import reducers from './reducers/reducers';
// And our Recipe component
import React, { Component } from 'react';
import { connect } from 'react-redux';
// Remember our thunk this is where we will need to make use of it
import { recipesFetchData } from '../actions/actions.js';
// We gonna use lodash to map over our recipe object
import _ from 'lodash'
class Recipe extends Component {
constructor(props) {
super(props);
import { combineReducers } from 'redux';
import getRecipes from './recipe_actions/get_recipes.js';
import loadingRecipes from './recipe_actions/loading_recipes.js';
const reducers = combineReducers({
recipes: getRecipes,
loadRecipes: loadingRecipes,
});
export default reducers;
import { LOADING_RECIPES } from '../../actions/actions';
export default function loadingRecipes(state = true, action) {
switch (action.type) {
case LOADING_RECIPES:
return action.payload;
}
return state;
}
import { GET_RECIPES } from '../../actions/actions';
export default function getRecipe(state = {}, action) {
switch (action.type) {
case GET_RECIPES:
return action.payload
}
return state;
}
import axios from 'axios';
// Exporting our actions
export const LOADING_RECIPES = 'LOADING_RECIPES';
export const GET_RECIPES = 'GET_RECIPES';
// An action to check if the recipes are loaded accepts true or false
export function loadingRecipes(loading) {
return {
type: LOADING_RECIPES,
// Then to get access to our API route we will use importer
var importRoutes = keystone.importer(__dirname);
// And finally set up the api on a route
var routes = {
api: importRoutes('./api'),
};
// Export our app routes
exports = module.exports = function (app) {
// Get access to the API route in our app
var keystone = require('keystone');
/**
* List Recipe
*/
// Getting our recipe model
var Recipe = keystone.list('Recipe');
// Creating the API end point
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
// This will be the entry point of our app
const App = () => {
return (
// We will add our components here
<div />
);