defaultProps ignored?

but I've a custom component with default props like --------- ./Custom.jsx export const Custom = ({ custom1, custom2, ...props }) => { ... }; Cutom.defaultProps = { custom1: 'C1', custom2: 'C2' }; export default Custom; ------------------ I'm using it like: import { Custom } from "../Custom" <Custom custom1="XXX" /> but I'm getting this error: TS2739: Type '{ custom1:string; }' is missing the following properties from type '{ ... }': custom2 now... why is it not using the defaultProps definition? is it possible to somehow disable it as I've a full library that is using .defaultProps in the component definitions? Thanks
2 Replies
genetic-orange
genetic-orange2y ago
Aren’t defaultProps class component only now? Is there a specific reason for you to not use the destructured props at the function definition? Also #ask-any-question is refine only, can you please share this kind of issues at maybe #off-topic ? 🙏
exotic-emerald
exotic-emerald2y ago
Hey @.simoneb, You can define default props for functional components like this: export const Custom = ({ label = “title”, age = 18 }: {label: string, age: number}) => { return ( … ) }