ttk-app-core
Version:
@ttk/recat enterprise develop framework
33 lines (32 loc) • 886 B
JavaScript
// app.js
import React from 'react'
import { useActions, useData, useCommit } from '@ttk/app-loader'
export default React.memo(Page)
function Page(props) {
const actions = useActions(props)
const commit = useCommit()
let title = useData([props, 'testData', 'title'])
let count = useData([props, 'testData', 'count'])
function onClick() {
actions.updateTitleAction('我是新的title')
}
function updateCount() {
commit([props,'testData'], {type: 'updateCount' , data:count+1})
}
return (
<div>
<div >
<label>title: </label>
<label>{title}</label>
</div>
<button onClick={onClick} >通过action更新Title</button>
<br />
<br />
<div>
<label>count: </label>
<label>{count}</label>
</div>
<button onClick={updateCount} >使用commit直接更新reducer</button>
</div>
)
}