import { Observable, IoC, useService } from '@vgerbot/use-service-react';
import { observable, action } from 'mobx';
@Observable()
class UserService {
@observable authorized = false;
@action login() {
this.authorized = true;
}
@action logout() {
this.authorized = false;
}
}
function App() {
return <IoC>
<UserStatus></UserStatus>
</IoC>
}
const UserStatus = observer(() => {
const userService = useService(UserService);
return <div>{userService.authorized ? <Logout></Logout> : <Login></Login>}</div>
})
function Login() {
const userService = useService(UserService);
return <button onClick={() => { userService.login() }}>Login</button>
}
function Logout() {
const userService = useService(UserService);
return <button onClick={() => { userService.logout() }}>Logout</button>
}
generated from y1j2x34/rollup-jest-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
A JS library offering a hook for leveraging IoC capabilities in React frameworks.
License
vgerbot-libraries/use-service
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
A JS library offering a hook for leveraging IoC capabilities in React frameworks.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published