Skip to content

PaginationItem reads SharedValue.value during render (Reanimated strict mode warning) #882

@evanwinter

Description

@evanwinter

Hey! First off, thanks for this awesome library - it's been great to work with.

Issue

I noticed that the Pagination.Custom component triggers Reanimated's strict mode warning when rendering:

WARN [Reanimated] Reading from `value` during component render. Please ensure that you don't access the `value` property nor use `get` method of a shared value while React is rendering a component.

Where it happens

In src/components/Pagination/Custom/PaginationItem.tsx (lines 111-112), animValue.value is read directly in the JSX for accessibility props:

<Pressable
  // ...
  accessibilityHint={animValue.value === index ? "" : `Go to ${accessibilityLabel}`}
  accessibilityState={{ selected: animValue.value === index }}
>

Possible fix

One approach could be to sync the selected state to regular React state:

const [isSelected, setIsSelected] = useState(false);

useDerivedValue(() => {
  runOnJS(setIsSelected)(animValue.value === index);
});

// Then in JSX
accessibilityHint={isSelected ? "" : `Go to ${accessibilityLabel}`}
accessibilityState={{ selected: isSelected }}

Happy to submit a PR if that would help!

Environment

  • react-native-reanimated-carousel: 4.0.3
  • react-native-reanimated: ~3.17.4
  • Platforms: iOS & Android

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions