Code Monkey home page Code Monkey logo

react-scenedirector's Introduction

react-scenedirector

Managing scenes/screens in React projects

Build Status Dependency Status devDependency Status codecov.io

Modeled after https://github.com/freezedev/lyria. The API is in the "figuring things out" mode.

Usage

import React from 'react';
import ReactDOM from 'react-dom';

import SceneDirector from 'react-scenedirector';

const Scene1 = ({ switchToScene }) => {
  const onClick = () => switchToScene('Scene2');

  return (
    <div>
      <button onClick={onClick}>Switch to Scene 2</button>
    </div>
  );
};

const Scene2 = ({ switchToScene }) => {
  const onClick = () => switchToScene('Scene1');

  return (
    <div>
      <button onClick={onClick}>Switch to Scene 1</button>
    </div>
  );
}

const App = () => (
  <SceneDirector
    scenes={{ Scene1, Scene2 }}
    initialScene="Scene1" />
);

ReactDOM.render(App, document.getElementBy('content'));

Props

scenes

Type: Object

Requires an object in the from { [String]: ReactNode }.

initialScene

Type: String

The name of the initial scene that will be shown

Switch through scenes is possible either with props.switchToScene or this.context.switchToScene. Switching between scenes using props will be deprecated in the future.

onSwitchScene

Type: Function

This function will be called once we switch to a scene. It will also be called for the initial scene.

Will this be available for React Native?

Yes, at some point... maybe. Not right now. But if you a pull request for that, I'd be eternally grateful.

react-scenedirector's People

Contributors

frostney avatar npmcdn-to-unpkg-bot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.