@actorize/react 中文文档教程
@actorize/react
[]()
这只是 @actorize/core
Getting Started
$ npm install @actorize/react
# or
$ yarn add @actorize/react
import { ActorizeProvider, useActorize } from '@actorize/react';
import {
dispatch
} from '@actorize/core';
import director from './director';
// ...
const MyCoolActor = () => {
const [state, setState] = useSate(0)
const actor = useActorize('cool-actor', {
onMessage: (msg) => {
if (msg.payload === 'INC') {
setState(state + 1)
}
},
});
return (
<div>
{state}
</div>
)
}
const ThatBigButton = () => {
const handleClick = () => {
dispatch(director, 'cool-actor', 'INC');
}
return (
<button onClick={handleClick} >Click Me</button>
)
}
const Wrapper = () => (
<ActorizeProvider director={director}>
<MyCoolActor />
<ThatBigButton />
</ActorizeProvider>
)
@actorize/react
[]()
this is just the React Extension for @actorize/core
Getting Started
$ npm install @actorize/react
# or
$ yarn add @actorize/react
import { ActorizeProvider, useActorize } from '@actorize/react';
import {
dispatch
} from '@actorize/core';
import director from './director';
// ...
const MyCoolActor = () => {
const [state, setState] = useSate(0)
const actor = useActorize('cool-actor', {
onMessage: (msg) => {
if (msg.payload === 'INC') {
setState(state + 1)
}
},
});
return (
<div>
{state}
</div>
)
}
const ThatBigButton = () => {
const handleClick = () => {
dispatch(director, 'cool-actor', 'INC');
}
return (
<button onClick={handleClick} >Click Me</button>
)
}
const Wrapper = () => (
<ActorizeProvider director={director}>
<MyCoolActor />
<ThatBigButton />
</ActorizeProvider>
)