I want a button to be able to scroll to a section where I have some questions, right now I have this code and if I click the button it doesn't do anything, it doesn't scroll, what am I doing wrong?
I have 3 files that I am using:
home.tsx (here is the front and here I use the other 2 components(files))
const scrollRef = useRef<SectionList>(null)<Questions questions={question} ref={scrollRef}/><AnotherComponent .... />.....<ButtonCard goToQuestions={() => { scrollRef.current?.scrollToLocation({ animated: true, itemIndex: 0, sectionIndex: 0, viewOffset: 0 }) }} />
Component(file) Questions.tsx
as send component prop "refLic"
interface Props { refLic?: React.RefObject<SectionList<any, DefaultSectionT>>}......<SectionList key='questions' ref={refLic} renderItem={({ item }) => item} sections={[ { title: '', data: [<List.Section title='Questions' titleStyle={styles.title}><FlatList data={questions.body.slice(0, itemsToShow)} renderItem={renderItem} /></List.Section> ] } ]} />
Component(file) ButtonCard.tsx
as send component prop "goToQuestions"
interface Props { goToQuestions: () => void}......<TouchableOpacity onPress={goToQuestions} />