我面临着 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) 我将 Yup 与 Formik 一起使用,但遇到了问题,我需要验证我的文件上传。验证有效,但我遇到了问题,因为我无法提交没有文件的表单。我需要将其设置为 notRequired,并且因为initialValue 未定义,所以它会测试该未定义的值。
我的代码:
attachment: Yup.mixed()
.nullable()
.notRequired()
.test("FILE_SIZE", "Uploaded file is too big.", value => value && value.size <= FILE_SIZE)
.test("FILE_FORMAT", "Uploaded file has unsupported format.", value => value && SUPPORTED_FORMATS.includes(value.type))
Run Code Online (Sandbox Code Playgroud)