Named State

같은 name으로 호출하면 같은 singleton store를 반환합니다.


컴포넌트 내부 호출을 기준으로 설계된 named mode

Named mode는 React 컴포넌트 내부에서 편하게 사용할 수 있습니다. 같은 name과 같은 storage option을 사용하면 같은 entry와 같은 반환 객체를 재사용합니다. 숫자 증가처럼 이전 값에 의존하는 업데이트는 setCount((prev) => prev + 1) 형태로 작성하세요.

tsx
import { createRxState } from "@byeolnaerim/global-rx-state";

function A_Component() {
  const { setCountInner, useCountInner } = createRxState(0, "countInner", { storage: "auto" });
  const countInner = useCountInner();

  return (
    <button onClick={() => setCountInner((prev) => prev + 1)}>
      {countInner}
    </button>
  );
}

function B_Component() {
  const { useCountInner } = createRxState(0, "countInner", { storage: "auto" });
  const countInner = useCountInner();

  return <span>현재 count: {countInner}</span>;
}
© 2026 Byeolnaerim. All rights reserved.소개개인정보처리방침