Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

69
Visualizações
Pass a Children component as an argument to a function that returns another component

I wanted to encapsulate a modal in a function that returns a new component, passing the children that will be inside this component as an argument, I tried this way below, but it's not working, the return function is recognized as an anonymous function, and not a component, and it doesn't render the children, what's wrong? Is there a better way to do this?

Modal.tsx File

export const useModal = (Chd: any) => ({ }: any) => {
        const anim = useRef(new Animated.Value(0)).current
        const [opened, setOpened] = useState(false)

    useEffect(() => {
        if (opened) {
            Animated.timing(
                anim,
                {
                    toValue: 1,
                    duration: 2000,
                    useNativeDriver: true
                }
            ).start();
        }
    }, [opened]);

    const open = () => { if (!opened) { setOpened(true); } };

    const close = () => {
        if (!opened) return;
        Animated.timing(
            anim,
            {
                toValue: 0,
                duration: 2000,
                useNativeDriver: true
            }
        ).start(() => setOpened(false));
    };

    var funcs = { open, close, anim };

    // open();
    // close();

    return (
        <ModalComponent
            transparent
            visible={opened}
        >
            <Container>
                <Chd {...funcs} />
            </Container>
        </ModalComponent>
    );
}

Dialog.tsx File

const Dialog = useModal(({ open, close, anim }: any) => {

useEffect(() => { open() /*Not Work, Dialog not rendering*/ }, [])

return (
    <Container>
        {
            <Animated.View style={{
                transform: [
                    {
                        scale: anim.interpolate({
                            inputRange: [0, 0.8, 1],
                            outputRange: [0, 1.2, 1]
                        })
                    }
                ]
            }}>
                <Center></Center>
            </Animated.View>
        }
    </Container>
    );
});

export default Dialog;
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda