GithubHelp home page GithubHelp logo

unix / backset Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 1.0 460 KB

Minimalist state tool for React apps.

Home Page: https://backset.now.sh

License: MIT License

JavaScript 11.06% TypeScript 88.94%
react-state backset

backset's Introduction

Backset

A minimalist state tool for React apps.

  • Very few APIs.
  • Based on React Hooks and Context.
  • Tracking and eliminate unnecessary re-renders.
  • No redundant template code.
  • Gzipped โ‰ˆ 1.5kb.

Easy to use

  • backset is based on React.Context.
  • backset is designed to let you write less code.

This is the simplest implementation of count under backset and React.Context, Obviously, backset is shorter and easier to read, if you have multiple components or pass more values, the advantage of backset will be more obvious.

You also can see their differences in the codesandbox editor.

Count example with backset

Count example with Native Context


Performance & Optimization

We all know that the native React.Context will render repeatedly, unless you use the React.Memo wrap component or the useMemo wrap render function, this requires a lot of repetitive code.

You don't have to think about these problems when using backset, it provides the useTracked API to automatically track state, this means:

  • Better performance without changing any code.
  • Still hooks, still your favorite style.
  • Switch at any time, no duplicate code.

Click to view this example online.

Automatically avoids unnecessary rendering


Experience & API Design

Although backset looks magical, it doesn't make any hacks.

backset can intelligently provide all types of inference, it can even check your properties by type, Using backset in your project is definitely a pleasure!

Automatically tips and constraints


Quick start

  1. Run yarn add backset or yarn i backset install it.
  2. Create a store and use it:
import { create } from 'backset'
const { useStores, useUpdates, withContext } = create({ title: 'Hello World' })

const Child = () => {
  const updates = useUpdates()
  return <button onClick={() => updates.title('Hello Backset')}>Edit</button>
}

const App = () => {
  const { title } = useStores()
  return <div>{title} <Child /></div>
}

export default withContext(App)

Edit this example on codesandbox.


Documentation


LICENSE

MIT

backset's People

Contributors

unix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

usdl

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.