Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@amoutonbrady/etat

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amoutonbrady/etat

The tiniest global store possible for Solid

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Etat

Etat means "state" in french

Experimental global store for Solid focused on size and extensibility. This is essentially a global and safe way to have Solid's stores via Context API. If you want a more thorough solution, check out solid-pebble.

Installation

$ npm install @amoutonbrady/etat
$ pnpm install @amoutonbrady/etat
$ yarn install @amoutonbrady/etat

Getting started

  1. Add the global EtatProvider

    // index.tsx
    
    import { render } from 'solid-js/web'
    import { EtatProvider } from '@amoutonbrady/etat';
    
    import { App } from './app';
    
    render(
      () => (
        <EtatProvider>
          <App />
        </EtatProvider>
      ), 
      document.getElementById('root'),
    );
    
  2. Define your stores globally

    // store.tsx
    
    import { createEtat } from '@amoutonbrady/etat`;
    
    export const useAuth = createEtat('auth', {
      token: '',
      get isAuthenticated() {
        return this.token.length > 0;
      },
    });
    
  3. Use them as you please accross the whole app

    // login.tsx
    
    import { useAuth } from './store.tsx';
    
    export function Login() {
      const [_, setAuth] = useAuth();
    
      function login() {
        return setAuth('token', 'abcde');
      }
    
      return <button type="button" onClick={login}>Login!</button>
    }
    
    // app.tsx
    
    import { Show } from 'solid-js';
    import { Login } from './login.tsx';
    import { useAuth } from './store.tsx';
    
    export function App() {
      const [auth] = useAuth();
    
      return (
        <Show
          when={!auth.isAuthenticated}
          fallback={<p>Your are logged in with the token {auth.token}</p>}
        >
          <Login />
        </Show>
      );
    }
    
    

API

  • createEtat<T>(id: string, initialValue: T): () => [Store<T>, StoreSetterFunction<T>]
    • id : This is a unique name that's being used to store the store value.
    • initialValue : This is the initial value of the store. It should ba an object. This will become a parameter of a createStore function.
  • EtatProvider : this is the global provider. Without this, the stores won't work. I didn't add any check for this.

FAQs

Package last updated on 21 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc