This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* ... */ | |
| import { StaticRouter } from "react-router-dom"; | |
| /* ... */ | |
| app.get( "/*", ( req, res ) => { | |
| const context = { }; | |
| const jsx = ( | |
| <StaticRouter context={ context } location={ req.url }> | |
| <Layout /> | |
| </StaticRouter> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import express from "express"; | |
| import path from "path"; | |
| import React from "react"; | |
| import { renderToString } from "react-dom/server"; | |
| import Layout from "./components/Layout"; | |
| const app = express(); | |
| app.use( express.static( path.resolve( __dirname, "../dist" ) ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ScrollPosition extends React.Component { | |
| constructor( ) { | |
| super( ); | |
| this.state = { position: 0 }; | |
| this.updatePosition = this.updatePosition.bind(this); | |
| } | |
| componentDidMount( ) { | |
| window.addEventListener( "scroll", this.updatePosition ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function withAuthentication(WrappedComponent) { | |
| const ModifiedComponent = (props) => { | |
| if (!props.isAuthenticated) { | |
| return <Redirect to="/login" />; | |
| } | |
| return (<WrappedComponent { ...props } />); | |
| }; | |
| const mapStateToProps = (state) => ({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const withProps = ( newProps ) => ( WrappedComponent ) => { | |
| const ModifiedComponent = ( ownProps ) => ( // the modified version of the component | |
| <WrappedComponent { ...ownProps } { ...newProps } /> // original props + new props | |
| ); | |
| return ModifiedComponent; | |
| }; | |
| const Details = ( { name, title, language } ) => ( | |
| <div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Details = ( { name, language } ) => ( | |
| <div> | |
| <p>{ name } works with { language }</p> | |
| </div> | |
| ); | |
| class Details extends React.Component { | |
| render() { | |
| const { name, language } = this.props; | |
| return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Details = ( { name, language } ) => ( | |
| <div> | |
| <p>{ name } works with { language }</p> | |
| </div> | |
| ); | |
| const Layout = ( { title, ...props } ) => ( | |
| <div> | |
| <h1>{ title }</h1> | |
| <Details { ...props } /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const condition = true; | |
| const App = () => { | |
| const innerContent = condition ? ( | |
| <div> | |
| <h2>Show me</h2> | |
| <p>Description</p> | |
| </div> | |
| ) : null; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const condition = true; | |
| const App = () => ( | |
| <div> | |
| <h1>This is always visible</h1> | |
| { | |
| condition && ( | |
| <div> | |
| <h2>Show me</h2> | |
| <p>Description</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import expect from "expect.js"; | |
| import reducer from "./reducers"; | |
| import actions from "./actions"; | |
| describe( "duck reducer", function( ) { | |
| describe( "quack", function( ) { | |
| const quack = actions.quack( ); | |
| const initialState = false; | |
| const result = reducer( initialState, quack ); |