If you are using shared values from Reanimated, you should use them only within useWindowDimensions.
useWindowDimensions
const { width } = useWindowDimensions(); // ... rest of the code
more in docs