Convert Figma logo to code with AI

coryhouse logoreact-slingshot

React + Redux starter kit / boilerplate with Babel, hot reloading, testing, linting and a working example app built in

9,741
2,944
9,741
88

Top Related Projects

Set up a modern web app by running one command.

The official, opinionated, batteries-included toolset for efficient Redux development

69,346

Next generation frontend tooling. It's fast!

127,829

The React Framework

30,309

Build Better Websites. Create modern, resilient user experiences with web fundamentals.

Declarative routing for React

Quick Overview

React Slingshot is a comprehensive starter kit for building React applications with a focus on rapid development and best practices. It includes a curated set of tools and configurations to streamline the development process, offering features like hot reloading, automated testing, and production build optimization out of the box.

Pros

  • Comprehensive setup with essential tools and configurations pre-configured
  • Includes hot reloading for faster development cycles
  • Automated testing setup with Jest and Enzyme
  • Production-ready build process with optimization features

Cons

  • May be overwhelming for beginners due to the number of tools and configurations included
  • Some included tools or configurations might not be necessary for every project
  • Requires regular maintenance to keep dependencies up-to-date
  • Opinionated setup might not align with every developer's preferences

Code Examples

  1. Creating a functional component:
import React from 'react';

const Welcome = ({ name }) => (
  <h1>Hello, {name}!</h1>
);

export default Welcome;
  1. Using React hooks for state management:
import React, { useState } from 'react';

const Counter = () => {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
};
  1. Making an API call with async/await:
import React, { useState, useEffect } from 'react';

const UserList = () => {
  const [users, setUsers] = useState([]);

  useEffect(() => {
    const fetchUsers = async () => {
      const response = await fetch('https://api.example.com/users');
      const data = await response.json();
      setUsers(data);
    };
    fetchUsers();
  }, []);

  return (
    <ul>
      {users.map(user => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
};

Getting Started

To get started with React Slingshot:

  1. Clone the repository:

    git clone https://github.com/coryhouse/react-slingshot.git
    
  2. Install dependencies:

    cd react-slingshot
    npm install
    
  3. Start the development server:

    npm start
    
  4. Open your browser and navigate to http://localhost:3000 to see the app running.

Competitor Comparisons

Set up a modern web app by running one command.

Pros of Create React App

  • Official React toolchain with strong community support and regular updates
  • Simplified setup process with zero configuration required
  • Extensive documentation and resources for beginners

Cons of Create React App

  • Less flexibility for advanced configurations without ejecting
  • Larger bundle size due to inclusion of unnecessary dependencies
  • Limited customization options for build processes

Code Comparison

React Slingshot:

import React from 'react';
import {render} from 'react-dom';
import { Provider } from 'react-redux';
import App from './components/App';
import configureStore from './store/configureStore';

Create React App:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

React Slingshot provides a more opinionated setup with Redux integration, while Create React App offers a simpler, more generic starting point. React Slingshot includes additional boilerplate for state management, whereas Create React App focuses on a minimal React setup, leaving state management choices to the developer.

Both projects aim to simplify React development, but React Slingshot offers more out-of-the-box features for experienced developers, while Create React App prioritizes ease of use for beginners and flexibility for various project types.

The official, opinionated, batteries-included toolset for efficient Redux development

Pros of Redux Toolkit

  • Official Redux package, providing standardized best practices
  • Simplifies Redux setup with built-in utilities like createSlice and configureStore
  • Includes RTK Query for efficient API calls and data fetching

Cons of Redux Toolkit

  • Less opinionated about project structure compared to React Slingshot
  • Requires additional setup for features like routing and testing
  • May have a steeper learning curve for developers new to Redux

Code Comparison

Redux Toolkit:

import { createSlice, configureStore } from '@reduxjs/toolkit'

const counterSlice = createSlice({
  name: 'counter',
  initialState: 0,
  reducers: {
    increment: state => state + 1,
  },
})

const store = configureStore({
  reducer: counterSlice.reducer,
})

React Slingshot:

import { createStore } from 'redux'
import rootReducer from './reducers'

const store = createStore(
  rootReducer,
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
)

Redux Toolkit offers a more concise and modern approach to Redux setup, while React Slingshot provides a complete boilerplate with additional features out of the box. The choice between them depends on project requirements and developer preferences.

69,346

Next generation frontend tooling. It's fast!

Pros of Vite

  • Faster build times and development server startup
  • Built-in support for TypeScript, JSX, and CSS modules
  • Lighter weight and more modern tooling approach

Cons of Vite

  • Less opinionated, requiring more configuration for complex setups
  • Smaller ecosystem and community compared to webpack-based solutions
  • May require additional plugins for certain features

Code Comparison

React-Slingshot (webpack-based):

const webpack = require('webpack');
const config = {
  entry: './src/index.js',
  output: { filename: 'bundle.js' },
  module: { rules: [/* ... */] },
  plugins: [new webpack.HotModuleReplacementPlugin()]
};

Vite:

// vite.config.js
export default {
  plugins: [react()],
  server: { hmr: true },
  build: { outDir: 'dist' }
};

Summary

Vite offers a more modern and faster development experience, particularly for smaller to medium-sized projects. It excels in quick startup times and efficient hot module replacement. React-Slingshot, being webpack-based, provides a more established ecosystem and may be better suited for complex applications with specific build requirements. The choice between the two depends on project needs, team familiarity, and desired development workflow.

127,829

The React Framework

Pros of Next.js

  • Built-in server-side rendering and static site generation
  • Automatic code splitting for faster page loads
  • Extensive ecosystem with built-in optimizations and plugins

Cons of Next.js

  • Steeper learning curve for developers new to server-side rendering
  • Less flexibility in project structure compared to React Slingshot
  • Potential overhead for simple applications that don't require SSR

Code Comparison

Next.js:

import Head from 'next/head'

export default function Home() {
  return (
    <div>
      <Head>
        <title>My Next.js App</title>
      </Head>
      <h1>Welcome to Next.js!</h1>
    </div>
  )
}

React Slingshot:

import React from 'react';

const App = () => {
  return (
    <div>
      <h1>Welcome to React Slingshot!</h1>
    </div>
  );
};

export default App;

Summary

Next.js offers powerful features like SSR and automatic optimizations, making it ideal for large-scale applications. React Slingshot provides a simpler boilerplate for React projects, offering more flexibility but fewer built-in features. The choice between them depends on project requirements and developer preferences.

30,309

Build Better Websites. Create modern, resilient user experiences with web fundamentals.

Pros of Remix

  • Full-stack framework with built-in server-side rendering and data loading
  • Seamless integration with modern web APIs and progressive enhancement
  • Strong focus on web standards and performance optimization

Cons of Remix

  • Steeper learning curve due to its full-stack nature
  • Less flexibility in choosing backend technologies compared to React Slingshot
  • Relatively newer project with a smaller ecosystem of plugins and extensions

Code Comparison

Remix (server-side data loading):

export async function loader({ params }) {
  const user = await getUser(params.id);
  return json({ user });
}

React Slingshot (client-side data fetching):

useEffect(() => {
  fetchUser(id).then(setUser);
}, [id]);

Key Differences

  • Remix is a full-stack framework, while React Slingshot is a client-side boilerplate
  • Remix emphasizes server-side rendering and data loading, React Slingshot focuses on client-side architecture
  • Remix has a more opinionated structure, React Slingshot offers more flexibility in project setup

Use Cases

  • Choose Remix for full-stack applications with a focus on performance and SEO
  • Opt for React Slingshot when building client-heavy SPAs with more freedom in backend choices

Declarative routing for React

Pros of React Router

  • Widely adopted and maintained routing solution for React applications
  • Extensive documentation and community support
  • Flexible and feature-rich, supporting nested routes, dynamic routing, and code-splitting

Cons of React Router

  • Focused solely on routing, lacking the full-stack development setup of React Slingshot
  • Requires additional configuration and integration with other tools for a complete development environment
  • May have a steeper learning curve for beginners compared to React Slingshot's opinionated setup

Code Comparison

React Router:

import { BrowserRouter, Route, Switch } from 'react-router-dom';

<BrowserRouter>
  <Switch>
    <Route exact path="/" component={Home} />
    <Route path="/about" component={About} />
  </Switch>
</BrowserRouter>

React Slingshot:

import { Route, Switch } from 'react-router-dom';

<Switch>
  <Route exact path="/" component={HomePage} />
  <Route path="/fuel-savings" component={FuelSavingsPage} />
</Switch>

Summary

React Router is a specialized routing library for React applications, offering robust routing capabilities and extensive community support. React Slingshot, on the other hand, provides a more comprehensive boilerplate for React development, including routing along with other development tools and configurations. While React Router excels in routing flexibility, React Slingshot offers a more opinionated and complete setup for beginners and rapid project initialization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README


Build status: Linux Build status: Windows Dependency Status Coverage Status

A comprehensive starter kit for rapid application development using React.

Why Slingshot?

  1. One command to get started - Type npm start to start development in your default browser.
  2. Rapid feedback - Each time you hit save, changes hot reload and linting and automated tests run.
  3. One command line to check - All feedback is displayed on a single command line.
  4. No more JavaScript fatigue - Slingshot uses the most popular and powerful libraries for working with React.
  5. Working example app - The included example app shows how this all works together.
  6. Automated production build - Type npm run build to do all this:

React Slingshot Production Build

Get Started

  1. Initial Machine Setup

    First time running the starter kit? Then complete the Initial Machine Setup.

  2. Click "Use this template"

    Click the green "Use this template" button at the top of this page and enter a name and description for your repo.

  3. Run the setup script

    npm run setup

  4. Run the example app

    npm start -s

    This will run the automated build process, start up a webserver, and open the application in your default browser. When doing development with this kit, this command will continue watching all your files. Every time you hit save the code is rebuilt, linting runs, and tests run automatically. Note: The -s flag is optional. It enables silent mode which suppresses unnecessary messages during the build.

  5. Review the example app.

    This starter kit includes a working example app that calculates fuel savings. Note how all source code is placed under /src. Tests are placed alongside the file under test. The final built app is placed under /dist. These are the files you run in production.

  6. Delete the example app files.

    Once you're comfortable with how the example app works, you can delete those files and begin creating your own app.

  7. Having issues? See Having Issues?.

Initial Machine Setup

  1. Install Node 8.0.0 or greater

    Need to run multiple versions of Node? Use nvm.

  2. Install Git.

  3. Disable safe write in your editor to assure hot reloading works properly.

  4. Complete the steps below for your operating system:

    macOS

    • Install watchman via brew install watchman or fswatch via brew install fswatch to avoid this issue which occurs if your macOS has no appropriate file watching service installed.

    Linux

    • Run this to increase the limit on the number of files Linux will watch. Here's why.

      echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p.

    Windows

    • Install Python 2.7. Some node modules may rely on node-gyp, which requires Python on Windows.

    • Install C++ Compiler. Browser-sync requires a C++ compiler on Windows.

      Visual Studio Express comes bundled with a free C++ compiler.

      If you already have Visual Studio installed: Open Visual Studio and go to File -> New -> Project -> Visual C++ -> Install Visual C++ Tools for Windows Desktop. The C++ compiler is used to compile browser-sync (and perhaps other Node modules).


Having Issues? Try these things first

  1. Make sure you ran all steps in Get started including the initial machine setup.

  2. Run npm install - If you forget to do this, you'll see this: babel-node: command not found.

  3. Install the latest version of Node.

  4. Make sure files with names that begin with a dot (.editorconfig, .gitignore, .npmrc) are copied to the project directory root. This is easy to overlook if you copy this repository manually.

  5. Don't run the project from a symbolic link. It may cause issues with file watches.

  6. Delete any .eslintrc that you're storing in your user directory. Also, disable any ESLint plugin / custom rules that you've enabled within your editor. These will conflict with the ESLint rules defined in this project.

  7. Make sure you don't have NODE_ENV set to production on your machine. If you do then the development dependencies won't be installed. Here's how to check.

  8. Install watchman with brew install watchman if you are having the following error after an initial npm start -s:

    2017-09-05 00:44 node[68587] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
    2017-09-05 00:44 node[68587] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
    events.js:160
          throw er; // Unhandled 'error' event
          ^
    
    Error: Error watching file for changes: EMFILE
        at exports._errnoException (util.js:1022:11)
        at FSEvent.FSWatcher._handle.onchange (fs.js:1406:11)
    
  9. Tip: Things to check if you get an npm run lint error or build error:

    • If ESW found an error or warning in your project (e.g. console statement or a missing semi-colon), the lint thread will exit with Exit status 1. To fix:

      1. Change the npm run lint script to "esw webpack.config.* src tools; exit 0"

      2. Change the npm run lint:watch script to "esw webpack.config.* src tools --watch; exit 0"

      Note: Adding exit 0 will allow the npm scripts to ignore the status 1 and allow ESW to print all warnings and errors.

    • Ensure the eslint/esw globally installed version matches the version used in the project. This will ensure the esw keyword is resolved.

  10. Rebuild node-sass with npm rebuild node-sass if you are having and error like Node Sass does not yet support your current environment on macOS XXX after an initial npm start -s.


Technologies

Slingshot offers a rich development experience using the following technologies:

TechDescriptionLearn More
ReactFast, composable client-side components.Pluralsight Course
ReduxEnforces unidirectional data flows and immutable, hot reloadable store. Supports time-travel debugging. Lean alternative to Facebook's Flux.Getting Started with Redux, Building React Applications with Idiomatic Redux, Pluralsight Course
React RouterA complete routing library for ReactPluralsight Course
BabelCompiles ES6 to ES5. Enjoy the new version of JavaScript today.ES6 REPL, ES6 vs ES5, ES6 Katas, Pluralsight course
WebpackBundles npm packages and our JS into a single file. Includes hot reloading via react-transform-hmr.Quick Webpack How-to Pluralsight Course
BrowsersyncLightweight development HTTP server that supports synchronized testing and debugging on multiple devices.Intro vid
JestAutomated tests with built-in expect assertions and Enzyme for DOM testing without a browser using Node.Pluralsight Course
TrackJSJavaScript error tracking.Free trial
ESLintLint JS. Reports syntax and style issues. Using eslint-plugin-react for additional React specific linting rules.
SASSCompiled CSS styles with variables, functions, and more.Pluralsight Course
PostCSSTransform styles with JS plugins. Used to autoprefix CSS
Editor ConfigEnforce consistent editor settings (spaces vs tabs, etc).IDE Plugins
npm ScriptsGlues all this together in a handy automated build.Pluralsight course, Why not Gulp?

The starter kit includes a working example app that puts all of the above to use.


Questions?

Check out the FAQ