Skip to content

Instantly share code, notes, and snippets.

View victor36max's full-sized avatar

Victor Chan victor36max

View GitHub Profile
@victor36max
victor36max / machine.js
Last active September 12, 2019 05:30
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@victor36max
victor36max / machine.js
Created September 9, 2019 08:05
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
static async getInitialProps({ isServer, store }) {
   // Fetch today NASA APOD
   await store.execSagaTasks(isServer, dispatch => {
     dispatch(fetchApodStart());
   });

   console.log('');
   console.log('###############################');
console.log('### Fetched today NASA APOD ###');
import {
  createStore,
  applyMiddleware,
  combineReducers,
  compose,
} from 'redux';
import createSagaMiddleware, { END } from 'redux-saga';

import reducers from './reducers';
static async getInitialProps({ isServer, store }) {
  store.dispatch({ type: type.MY_ACTION });
  console.log(store.getState());
  return {};
}
import { Component } from 'react';
import axios from 'axios'

class App extends Component {

  static async getInitialProps() {
    let response = await axios.get('http://localhost:3000/api/posts');
    return { posts: response.data };
  }
import Document, { Head, Main, NextScript } from 'next/document'
import flush from 'styled-jsx/server'

export default class MyDocument extends Document {
  static getInitialProps({ renderPage }) {
    const { html, head, errorHtml, chunks } = renderPage()
    const styles = flush()
    return { html, head, errorHtml, chunks, styles }
  }
import { Component } from 'react';

class App extends Component {
  render() {
    return (
      <div>Hello World</div>
    );
  };
}
const keystone = require('keystone');

// Setup Route Bindings
exports = module.exports = nextApp => keystoneApp => {

	// Next request handler
	const handle = nextApp.getRequestHandler();

	keystoneApp.get('/api/posts', (req, res, next) =&gt; {
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').config();

// Next app
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });