diff --git a/README.CN.md b/README.CN.md index c5181e8a2..794bb782d 100644 --- a/README.CN.md +++ b/README.CN.md @@ -208,6 +208,31 @@ define('my-counter', class extends WeElement { render(, 'body') ``` +你也可以定义成纯函数的形式: + +```js +import { define, render } from 'omi' + +define('my-counter', function() { + const [count, setCount] = this.use({ + data: 0, + effect: function() { + document.title = `The num is ${this.data}.` + } + }) + + return ( +
+ + {count} + +
+ ) +}) + +render(, 'body') +``` + ## 快速入门 ### 安装 diff --git a/README.md b/README.md index 0917419c4..23ff790bc 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,31 @@ define('my-counter', class extends WeElement { render(, 'body') ``` +You can also be defined as a form of pure functions: + +```js +import { define, render } from 'omi' + +define('my-counter', function() { + const [count, setCount] = this.use({ + data: 0, + effect: function() { + document.title = `The num is ${this.data}.` + } + }) + + return ( +
+ + {count} + +
+ ) +}) + +render(, 'body') +``` + ## Getting Started ### Install