question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Library: react-ridge-state

See original GitHub issue

I’m trying out my own state library it works great so far, do not see any error logs! Only problem is does not have a reducer but I created my own dispatch function.

Do you think the following is suitable in comparison to other libraries?

import React, { unstable_useTransition as useTransition } from 'react';
import {
  newRidgeState,
  useRidgeState,
  getRidgeState,
  setRidgeState,
} from 'react-ridge-state';

import {
  syncBlock,
  useRegisterIncrementDispatcher,
  ids,
  useCheckTearing,
  initialState,
  reducer,
} from '../common';

const globalState = newRidgeState(initialState);

const dispatch = (action) => {
  const old = getRidgeState(globalState);
  setRidgeState(globalState, reducer(old, action));
};

const Counter = React.memo(() => {
  const [count] = useRidgeState(globalState);
  syncBlock();
  return <div className="count">{count.count}</div>;
});

const Main = () => {
  const [state] = useRidgeState(globalState);
  useCheckTearing();
  useRegisterIncrementDispatcher(
    React.useCallback(() => {
      dispatch({ type: 'increment' });
    }, [])
  );
  const [localCount, localIncrement] = React.useReducer((c) => c + 1, 0);
  const normalIncrement = () => {
    dispatch({ type: 'increment' });
  };
  const [startTransition, isPending] = useTransition();
  const transitionIncrement = () => {
    startTransition(() => {
      dispatch({ type: 'increment' });
    });
  };

  return (
    <div>
      REACT_RIDGE_STATE
      <button type="button" id="normalIncrement" onClick={normalIncrement}>
        Increment shared count normally (two clicks to increment one)
      </button>
      <button
        type="button"
        id="transitionIncrement"
        onClick={transitionIncrement}
      >
        Increment shared count in transition (two clicks to increment one)
      </button>
      <span id="pending">{isPending && 'Pending...'}</span>
      <h1>Shared Count</h1>
      {ids.map((id) => (
        <Counter key={id} />
      ))}
      <div className="count">{state.count}</div>
      <h1>Local Count</h1>
      {localCount}
      <button type="button" id="localIncrement" onClick={localIncrement}>
        Increment local count
      </button>
    </div>
  );
};

const App = () => <Main />;

export default App;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
dai-shicommented, May 18, 2020

I will check that issue later. Been there done that. It’s extremely tricky to keep all states in React and provide Recoil API (not impossible though).

For the other path (= not global), I developed react-tracked.

2reactions
dai-shicommented, May 16, 2020

Looks good. It’s close to the case of Recoil, which I added lately. Please check that out and compare with it.

https://github.com/web-ridge/react-ridge-state/blob/master/src/index.ts Just had a quick look. Small and clean. Nice. If I understand it correctly, it suffers from the tearing issue. As I keep saying, that doesn’t mean really bad, but what can be done with it is to use use-subscription now or wait for useMutableSource.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-ridge-state - npm
react-ridge-state is a very simple global state management library for React and React Native. Latest version: 4.2.9, last published: 5 ...
Read more >
React Ridge State - GitHub
Checkout our other libraries · Simple form library for React Native with great UX for developer and end-user react-native-use-form · Smooth and fast...
Read more >
react-ridge-state - npm Package Health Analysis - Snyk
react-ridge-state is a very simple global state management library for React and React Native For more information about how to use this package...
Read more >
react-ridge-state | Frontend Utils library - kandi - Open Weaver
react-ridge-state is a TypeScript library typically used in User Interface, Frontend Utils, React Native, React applications. react-ridge-state has no bugs, ...
Read more >
react-ridge-state examples - CodeSandbox
Learn how to use react-ridge-state by viewing and forking ... Aboutreact-ridge-state is a very simple global state management library for React and React ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found