Closed ElBaDaNoS closed 6 months ago
Have you followed babel setup instructions? https://github.com/preactjs/signals/tree/main/packages/react#react-integration
You're not calling useSignals()
, so are you using the Babel plugin?
Minimal reproduction please, not a hundred lines of component code.
Have you followed babel setup instructions? https://github.com/preactjs/signals/tree/main/packages/react#react-integration
Indeed, I revisited the Babel setup instructions as you suggested and found that I hadn't properly configured the Babel plugin for Preact signals. After updating my Vite configuration to include the @preact/signals-react-transform plugin within the React plugin's Babel settings, it started working as expected. Here's the snippet I added to vite.config.ts:
plugins: [
react({
babel: {
plugins: [['module:@preact/signals-react-transform']],
},
}),
],
This change made my React components correctly respond to signal changes.
Thank you for your help!
Environment:
React version: 18.2.0 @preact/signals-react version: 2.0.0 Issue Description: The collapsed signal from @preact/signals-react is not causing visual updates in the sidebar component when its value is toggled via a button click. There is no change in the sidebar's width or the toggle icon's shape upon the click event. Interestingly, the collapsed.value only updates in the console log after the component files are saved in VSCode without any actual code changes.
Steps to Reproduce:
Define a collapsed signal with @preact/signals-react. Bind the signal to a className that conditionally sets the sidebar's width. Implement a button that toggles the collapsed signal's value. Expected Behavior: Clicking the button should collapse or expand the sidebar, and the toggle icon should change shape, reflecting the collapsed signal's value.
Actual Behavior: The sidebar does not change its width, nor does the toggle icon change shape upon interaction. Strangely, when the related source files are saved in VSCode without any modifications, the expected behavior is momentarily triggered.
Additional Context: This inconsistent behavior suggests a potential issue with how state persistence or HMR (Hot Module Replacement) is handled in the development environment.
Here is my code for the SideBar component:
and here is my code for the ToogleIcon component:
`