preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.64k stars 89 forks source link

Re-render doesn't work as expected using @preact/signals-react. #463

Closed NehaLakma02 closed 7 months ago

NehaLakma02 commented 7 months ago

I thought of introducing signals in my project, watched few videos and read the documentation. Replaced one state with signal in one the files, just to test first and it doesn't work.

configuration: vite

Screenshot 2023-12-14 at 11 08 55

When I click on view geofence modal open but in the child modal when I trigger close modal it doesn't work.

Screenshot 2023-12-14 at 11 07 13

XantreGodlike andrewiggins

rschristian commented 7 months ago

Please provide an actual, minimal reproduction -- screenshots (and collapsed ones, at that) show us no environment info or complete usage information. They're not very helpful in diagnosing an issue.

Foorack commented 7 months ago

Happening me as well, I believe it is because "@preact/signals-react-transform" is needed, and neither of us have it. I am currently looking into how to configure it with Vite, as I don't have babel.

Foorack commented 7 months ago

Got it working by editing vite.config.ts

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        react({
            babel: {
                plugins: [['module:@preact/signals-react-transform']],
            },
        }),
    ],
});

Also had to npm install --save-dev @preact/signals-react-transform (or Yarn/Bun equivalent).

andrewiggins commented 7 months ago

Glad to hear you got it working! Thanks for posting your fix back here.

camstuart commented 5 months ago

Thanks @Foorack that was exactly what I needed! This approach to state management is awesome. Great work to the preact team 👌