All Projects → solkimicreb → React Easy Params

solkimicreb / React Easy Params

Licence: mit
🔗 Auto synchronize your state with the URL and LocalStorage.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Easy Params

agile
🌌 Global State and Logic Library for JavaScript/Typescript applications
Stars: ✭ 90 (+23.29%)
Mutual labels:  reactive, state
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (+260.27%)
Mutual labels:  url, front-end
purescript-pop
😃 A functional reactive programming (FRP) demo created with PureScript events and behaviors.
Stars: ✭ 33 (-54.79%)
Mutual labels:  front-end, reactive
url
Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
Stars: ✭ 69 (-5.48%)
Mutual labels:  url, routing
Reatom
State manager with a focus of all needs
Stars: ✭ 567 (+676.71%)
Mutual labels:  reactive, state
golgi
A composable routing library for Haxe.
Stars: ✭ 37 (-49.32%)
Mutual labels:  url, routing
react-mobx-router5
React components for routing solution using router5 and mobx
Stars: ✭ 58 (-20.55%)
Mutual labels:  reactive, routing
mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (+2.74%)
Mutual labels:  state, localstorage
Effector
The state manager ☄️
Stars: ✭ 3,572 (+4793.15%)
Mutual labels:  reactive, state
Django Multiurl
Have you ever wanted multiple views to match to the same URL? Now you can.
Stars: ✭ 268 (+267.12%)
Mutual labels:  routing, url
url-trailing-slash
Allows enforcing URL routes with or without trailing slash
Stars: ✭ 35 (-52.05%)
Mutual labels:  url, routing
Mobx React Form
Reactive MobX Form State Management
Stars: ✭ 1,031 (+1312.33%)
Mutual labels:  reactive, state
atomic-state
Atomic State is a state management library for React
Stars: ✭ 15 (-79.45%)
Mutual labels:  state, localstorage
deep-state-observer
State library for high performance applications.
Stars: ✭ 25 (-65.75%)
Mutual labels:  reactive, state
node-match-path
Matches a URL against a path. Parameters, wildcards, RegExp.
Stars: ✭ 30 (-58.9%)
Mutual labels:  url, routing
immerx-state
Reactive, fractal and no-nonsense state management with Immer
Stars: ✭ 19 (-73.97%)
Mutual labels:  reactive, state
Mobx Rest
REST conventions for Mobx
Stars: ✭ 164 (+124.66%)
Mutual labels:  reactive, state
Store
A beautifully-simple framework-agnostic modern state management library.
Stars: ✭ 204 (+179.45%)
Mutual labels:  reactive, state
Ffrouter
Powerful and easy-to-use URL routing library in iOS that supports URL Rewrite(强大、易用、支持 URL Rewrite的 iOS 路由库)
Stars: ✭ 263 (+260.27%)
Mutual labels:  routing, url
Bidi
Bidirectional URI routing
Stars: ✭ 941 (+1189.04%)
Mutual labels:  routing, url

React Easy Params

🔗 Auto synchronize your state with the URL and the LocalStorage.

Build Coverage Status JavaScript Style Guide Package size Version dependencies Status License

Browser support

Table of Contents

Introduction

Easy Params is a tool for small apps - without client-side routing. It exposes two objects and an array, which synchronize with the corresponding browser APIs on mutations.

  • The params object is reflected in the URL query parameters.
  • The path array is reflected in the URL pathname.
  • The storage object is persisted in the localStorage.
Synchronization Demo
import React from 'react'
import { view } from 'react-easy-state'
import { params, path } from 'react-easy-params'

const updatePath = ev => path[0] = ev.target.value
const updateParam = ev => params.name = ev.target.value

export default view(() =>
  <div>
    <div>Path: <input onChange={updatePath} value={path[0]} /></div>
    <div>Param: <input onChange={updateParam} value={params.name} /></div>
  </div>
)

Use it together with React Easy State for an awesome developer experience.

Installation

npm install react-easy-params

API

params

The params object is reflected in the URL query parameters. You should store primitive values - which define the current state - in it. Storing primitive user inputs in the URL query makes you page shareable and reloadable.

The synchronization is one directional. The URL always synchronizes with the params object, but the params object won't synchronize with the URL on browser history events. It will synchronize once - at page load - though.

setParams(object)

Replaces the current params with the passed object. You should generally mutate params directly instead.

storage

The storage object is persisted in the localStorage. You should store session related information - like the current API token or preferred site theme - in it.

The synchronization is one directional. The localStorage synchronizes with the storage object, but the storage object won't synchronize with the localStorage on manual manipulation with localStorage.setItem(). It will synchronize once - at page load - though.

setStorage(object)

Replaces the current storage with the passed object. You should generally mutate storage directly instead.

path

The path array is reflected in the URL pathname. It is provided for the sake of completeness, you should usually use the params object instead.

The synchronization is one directional. The URL always synchronizes with the path array, but the path array won't synchronize with the URL on browser history events. It will synchronize once - at page load - though.

setPath(array)

Replaces the current path with the passed array. You should generally mutate path directly instead.

Examples with live demos

Beginner

Advanced

  • TodoMVC (source) (codesandbox): a classic TodoMVC implementation, which persists the todos in localStorage and reflects the current filter in the URL query.
  • Beer Finder (source) (codesandbox): an app with async actions and a mix of local and global state, which finds matching beers for your meal. It reflects the search parameter in the URL query to make it shareable.

Relation with React Easy State

params, path and storage are Easy State stores. If you use them inside your components, they re-render the component on their mutations - to reflect the changes. On top of this they are also reflected in the corresponding browser API.

Platform support

  • Node: 6 and above
  • Chrome: 49 and above
  • Firefox: 38 and above
  • Safari: 10 and above
  • Edge: 12 and above
  • Opera: 36 and above
  • IE is not supported

This library is based on non polyfillable ES6 Proxies. Because of this, it will never support IE.

Alternative builds

This library detects if you use ES6 or commonJS modules and serve the right format to you. The exposed bundles are transpiled to ES5 to support common tools - like UglifyJS minifying. If you would like a finer control over the provided build, you can specify them in your imports.

  • react-easy-params/dist/es.es6.js exposes an ES6 build with ES6 modules.
  • react-easy-params/dist/es.es5.js exposes an ES5 build with ES6 modules.
  • react-easy-params/dist/cjs.es6.js exposes an ES6 build with commonJS modules.
  • react-easy-params/dist/cjs.es5.js exposes an ES5 build with commonJS modules.

If you use a bundler, set up an alias for react-easy-params to point to your desired build. You can learn how to do it with webpack here and with rollup here.

Contributing

Contributions are always welcome. Just send a PR against the master branch or open a new issue. Please make sure that the tests and the linter pass and the coverage remains decent. Thanks!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].