Skip to content

Instantly share code, notes, and snippets.

@xpsteven
Last active April 18, 2019 01:06
Show Gist options
  • Save xpsteven/915ca235c2caefed95b5b68fbfc37d8b to your computer and use it in GitHub Desktop.
Save xpsteven/915ca235c2caefed95b5b68fbfc37d8b to your computer and use it in GitHub Desktop.
React Function Component Pattern 1:用 Factory 封裝靜態變數
/** MyForm 實作 */
const MyForm: React.FC<IMyFormStaticProps & IMyFormProps> = (props) => {
return (
<form />
);
};
/** 工廠函數 */
export default function MyFormFactory(sProps: IMyFormStaticProps) {
return (props: IMyFormProps) => (
<MyForm {...props} {...sProps} />
);
}
/** 靜態 props */
export interface IMyFormStaticProps {
sName: string;
}
/** 執行時期 props */
export interface IMyFormProps {
style: React.CSSProperties;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment