npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cra-template-rear

v2.0.0

Published

React template bundled with redux's history and router

Downloads

3

Readme

Rear CRA Template

Opinionated create-react-app template bundled with react-redux and react-router.

Table of contents

Installation

CRA Template

To install this template as a create-react-app template type:

npx create-react-app <your_app> --template rear

After the installation process has completed, go into your newly created app directory and run the setup script.

cd <your_app>
yarn setup

Create Rear App

A simpler way to install this template is by using the create-rear-app

npx create-rear-app <your_app>

Git Repository

You can also install this template directly from git by typing:

git clone https://github.com/erremauro/react-template <PROJECT_DIR>
cd <PROJECT_DIR> && git init && yarn install

Configuring your environments

You can configure your production and development URLs inside:

  • ./src/core/site-url/site-url.js
  • ./src/core/site-url/api-url.js

Structure

This template differs between components, containers, actions and reducers.

src/
├── actions
├── components
├── containers
├── core
└── reducers

Root Directory

A link to the src directory is created during the postinstall procedure. You can import files from the root directory using @ (e.g. @/components to import files from ./src/components).

Components

Components are reusable react components stored in ./src/components.

Containers

Containers are Higher Order components that render application views and manage application state via redux providers. They are stored in ./src/containers.

Actions and Reducers

Reducers stored in ./src/reducers keeps track of application states changes triggered by actions stored in ./src/actions (usually connected as container's props via redux providers).

Core

Common libraries are stored in ./src/core.

Custom Scripts

The template has a set of scripts to help you bootstrap containers, components and actions. All script can be found in the ./scripts directory.

Creating a new component

Create a new React Component in the ./src/components directory.

yarn create-component <NAME>

Creating a new container

Create a new React Component in the ./src/containers directory that is connected to a redux action provider.

yarn create-container <NAME>

Creating actions

Create a new set of actions and a reducer in ./src/actions and ./reducers

yarn create-actions <NAME>

Once the reducer has been created it must be manually added to ./src/reducers/index.js reducers list.

Using SASS

You can configure your project for using Sass or CSS stylesheet format in package.json's rearConfig section by changing the sass property.

{
  "rearConfig": {
    "sass": true
  }
}

You can then run yarn setup to reconfigure your project.

Note: During the configuration process the stylesheets are just renamed. No changes to the content is made. Bear in mind that if you choose to downgrade to CSS from Sass, you'll need to update the content that uses Sass specifc syntax.

API Middleware

This template has a redux middleware to make API calls already setup for you. To make an api call, return an API_CALL object from an action.

// src/actions/FooBar/FooBarActions.js

import { FooBarActionType as ActionType } from './FooBarActionType';

function myAction(id, model) {
  return({
    API_CALL: {
      types: [
        ActionType.MY_ACTION_REQUEST,
        ActionType.MY_ACTION_SUCCESS,
        ActionType.MY_ACTION_FAILURE
      ],
      endpoint: `myendpoint/${id}`,
      params: model
    }
  })
}

export const myAction = (id, model) => dispatch => dispatch(myAction(id, model));

Note that the endpoint parameter must be relative to the api url specified in ./src/core/site-url/api-url.js or a full URL (i.e. https://api.site.com/endpoint.json).

type API_CALL = {
  types: Array<string>,
  endpoint: string,
  params?: object,
  payload?: object,
  method?: string,
  dataType?: string
}

Use params to make GET requests passing query parameters and payload to pass data via POST requests. If you need to send a payload using other methods, explicity specify the method name (i.e. method: 'PUT', to make PUT requests).

API responses can be then processed to update reducer's states:

// src/reducers/myReducer.js

function updateState(newState) {
  currentState = Object.assign(currentState, newState);
  return currentState;
}

export default (state = initialState, action) => {
  switch (action.type) {
    case ActionType.MY_ACTION_SUCCESS:
      return updateState(action.response);
    default:
      return state;
  }
}

Or error handled in containers:

// src/containers/MyContainer/MyContainer.js

class MyContainer extends Component {
  loadData() {
    this.props.myAction().then(action => {
      if (action.type === ActionType.MY_ACTION_FAILURE) {
        // handle api response error
      }
    });
  }
}