Git Product home page Git Product logo

generic-react-component's Introduction

generic-react-component

Basic scaffolding for creating React components.

Set up your repo

  1. Create and move into your component's directory
    mkdir your-shiny-component && cd your-shiny-component
    
  2. Clone the repo
    git clone [email protected]:ryanwalters/generic-react-component.git
    
  3. Update the remote
    git remote rm origin
    git remote add origin <new git repo url>
    
  4. Rename the component
    • Change name in package.json
    • Search and replace GenericComponent -> YourShinyComponent
  5. Commit and push the new component. Note: the -u flag is only needed this once to set the upstream repo.
    git commit -am "initial commit"
    git push -u origin master
    

Set up your environment to work locally on your component

Component directory

cd ~/your-shiny-component
npm install
npm link

This installs our dependencies and allows us to use this dev version of the component in other projects as if it were installed as a dependency. npm link documentation

Project directory

cd ~/big-project
npm link your-shiny-component

This lets us use your-shiny-component from within the project as if it were a normal dependency.

import React from 'react';
import YourShinyComponent from 'your-shiny-component';

class App extends React.Component {
    
    render() {
        return (
            <div>
            	Just look how shiny: <YourShinyComponent/>
            </div>
        )
    }
}

export default App;

Working on your component

You should probably have two terminal windows open. One terminal for the component, one for the project.

Inside the component terminal, run npm start. This starts up webpack and watches your component, recompiling when a change is made.

Removing the link

cd ~/big-project
npm unlink your-shiny-component

cd ~/your-shiny-component
npm unlink

Credits:

Borrowed much of this from How to create a React component and publish it on NPM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.