-1

the sample code is here.
Please help me to unit test this peace of code.

    import { View, Text } from 'react-native'
    import React, { useRef, useEffect } from 'react'
    import { Modalize } from 'react-native-modalize'
        
    const TestComponent = () => {
        const myRef = useRef()
        useEffect(() => {
          myRef.current.open()
        })
        return (
          <Modalize ref={myRef} alwaysOpen={400}>
            <View>
              <Text>Hello</Text>
            </View>
          </Modalize>
        )
    }

1 Answers1

0

Try this way

export const App = () => {
  const modalizeRef = useRef<Modalize>(null);

  const onOpen = () => {
    modalizeRef.current?.open();
  };

  return (
    <>
      <TouchableOpacity onPress={onOpen}>
        <Text>Open the modal</Text>
      </TouchableOpacity>

      <Modalize ref={modalizeRef}>...your content</Modalize>
    </>
  );
};

Detail docs are here

Nooruddin Lakhani
  • 7,507
  • 2
  • 19
  • 39