Skip to content

solid/reactivity inconsistently handles signals and memos when passed to functions #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Huliiiiii opened this issue Apr 7, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Huliiiiii
Copy link

Huliiiiii commented Apr 7, 2025

const createCounter = (incrValue: () => number) => {
    const [count, setCount] = createSignal(0)
    return {
      count,
      incr: () => setCount((v) => v + incrValue()),
    }
  }

const [incr, setIncr] = createSignal(1)

const memo = createMemo(() => incr())

const counter = createCounter(incr) // Ok
const counter = createCounter(memo) // Error: The reactive variable 'memo' should be used within JSX, a tracked scope (like createEffect), or inside an event handler function, or else changes will be ignored.

Passing memo to functions like createCounter should not cause errors.

@Huliiiiii Huliiiiii added the bug Something isn't working label Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants