@jswork/with-props
v1.0.1
Published
Enhance component with preset properties.
Downloads
6
Maintainers
Readme
with-props
Enhance component with preset properties.
installation
npm install @jswork/with-props
usage
import withProps from '@jswork/with-props';
import React from 'react';
interface MyComponentProps {
title: string;
content: string;
}
const MyComponent: React.FC<MyComponentProps> = (props) => {
const { title, content } = props;
return React.createElement('div', null,
React.createElement('h1', null, title),
React.createElement('p', null, content)
);
};
// 使用 withProps 直接传递 defaultProps 和组件
const EnhancedComponent = withProps({ title: 'Default Title' }, MyComponent);
const App: React.FC = () => {
return React.createElement('div', null,
React.createElement(EnhancedComponent, { content: 'Custom Content' })
);
};
export default App;
license
Code released under the MIT license.