相关疑难解决方法(0)

使用 ForwardedRef 反应 FC

我面临着 ref 问题 - 我需要引用函数组件并将 props 传递给它。到目前为止,我得到了我的父组件和子组件。在我的父组件中,我需要对我的孩子使用 ref 。我需要在父组件中使用projectSectionItem。

家长:

const projectSectionItem = useRef<HTMLDivElement>(null);

        return i.showOnHP === 1 ?
            <Project key={index}
                url={`${URL}${i.button_image.image}`}
                client={i.client_name}
                project={i.project.en}
                btn_color={"#000"}
                btn_text={i.button_text}
                href={`/cases/${i.slug}`}
                ref={projectSectionItem}
            >
                {index === 0 ?
                    <ScrollList>
                        {data.map((i, index) => { return <ScrollListItem data-index={index} key={index} ref={projectIndicator} onClick={(e: React.MouseEvent<HTMLLIElement>) => scrollToNextProject(e)} /> })}
                    </ScrollList>
                    : null}
            </Project>
                : null;
        })}
Run Code Online (Sandbox Code Playgroud)

孩子:

type APIProps = {
    url?: string,
    client?: string,
    project?: string,
    btn_text?: string,
    btn_color?: string,
    href?: string,
}

type HWWProps = {
    order_client?: number, …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×1

reactjs ×1

typescript ×1