简体   繁体   English

如何使用 typescript 将道具从父母传递给孩子并做出反应?

[英]How to pass props from parent to child using typescript and react?

i want to pass props from parent to child using react and typescript. i am not sure how to add it to type.我想使用 react 和 typescript 将道具从父母传递给孩子。我不确定如何将其添加到类型中。

below is my code,下面是我的代码,

function Parent () {
    return (
        <DateRangePicker
            onDatesChange={onDatesChange}
            focusedInput={focusedInput}
            onFocusChange={onFocusChange}
        />
    );
}

type Props = Omit<
    DayPickerRangeControllerShape,
    'numberOfMonths' | 'hideKeyboardShortcutsPanel' | 'noBorder'
>;

function DateRangePicker(props: Props) {
    return (
        <Wrapper>
            <DayPickerRangeController
                {...props}
                numberOfMonths={2}
                focusedInput={focusedInput} //this is not detected
                onFocusChange={onFocusChange} //this is not detected
            />
        </Wrapper>
    );
}

how can i add the focusedInput and onFocusChange props to type Props.我如何添加 focusedInput 和 onFocusChange 道具来键入道具。 right now it gives me error.现在它给了我错误。 cannot find name "focusedInput".找不到名称“focusedInput”。 cannot find name "onFocusChange"找不到名称“onFocusChange”

could someone help me with this.有人可以帮我解决这个问题吗? thanks.谢谢。

...
interface IProps {
  focusedInput: Function
  onFocusChange: Function
}

type Props = Omit<
    DayPickerRangeControllerShape,
    'numberOfMonths' | 'hideKeyboardShortcutsPanel' | 'noBorder'
> & IProps;

function DateRangePicker(props: Props) {
    const {focusedInput, onFocusChange} = props
    return (
        <Wrapper>
            <DayPickerRangeController
                {...props}
                numberOfMonths={2}
                focusedInput={focusedInput} //this is not detected
                onFocusChange={onFocusChange} //this is not detected
            />
        </Wrapper>
    );
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何传递来自不同组件(关于和联系)的道具? 不是父母对孩子。 使用反应 typescript - How to pass props from different component(about and contact)? not parent to child. Using react typescript 如何使用组合模式将 React 道具从父母传递给孩子 - How to pass React props from parent to child using composition pattern 如何在反应中将道具从父母传递给孩子? - How to pass props from parent to child in react? React &amp; TypeScript 如何通过道具在 onClick 将数据从孩子传递给父母 - React & TypeScript how pass data from child to parent at onClick via props 反应:如何将道具从孩子传递给父母到另一个孩子? - React: how to pass props from child to parent to another child? 使用 React Hooks 将 props 从父母传递给孩子 function - Using React Hooks to pass props down from a parent to a child function 如何在 React.js 中将 state 作为道具从父母传递给孩子,然后从该孩子传递给它的孩子 - How to pass state from parent to child as props then from that child to it s child as props in React.js 如何在 React 中将道具从孩子传递给父母? - How do I pass props from child to parent in React? 如何以这种格式将道具或状态从父级传递给子级反应 - How to pass props or state from parent to child react in this format 如何在React Router上将Pros数据从父级传递给子级 - How to pass `props` data from parent to child on react router
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM