Skip to content

Commit

Permalink
docs: upt usage
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Sep 1, 2024
1 parent 6b2cbdb commit b2a7d1a
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,32 @@ npm install @jswork/react-with-props

## usage
```js
import reactWithProps from '@jswork/react-with-props';

// usage goes here.
import withProps from '@jswork/react-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;
```

## types
Expand Down

0 comments on commit b2a7d1a

Please sign in to comment.