Skip to content

Latest commit

 

History

History
57 lines (44 loc) · 1.62 KB

README.md

File metadata and controls

57 lines (44 loc) · 1.62 KB

with-props

Enhance component with preset properties.

version license size download

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.