This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| name: 'App’, | |
| setup(props, context) { | |
| useEventBusListener(MY_EVENT, handleMyEvent) | |
| useActivityTracker() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function useActivityTracker() { | |
| const userActivityTimeout = ref(null) | |
| const lastUserActivityAt = ref(Date.now()) | |
| function activateActivityTracker() {... } | |
| function deactivateActivityTracker() {... } | |
| function resetActivityTimeout() {... } | |
| function userActivityThrottler() {... } | |
| onBeforeMount(() => { | |
| activateActivityTracker() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function useEventBusListener(eventName, handler) { | |
| onMounted(() => EventBus.$on(eventName, handler)) | |
| onUnmounted(() => EventBus.$off(eventName, handler)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function load() { | |
| const id = props.match.params.id; // params -> from url | |
| const robot = await robotService.getRobotById(id) | |
| setRobot(robot) | |
| } | |
| useEffect(() => { | |
| load(); | |
| }, [props.match.params.id]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async componentDidMount() { | |
| const id = this.props.match.params.id; // params -> from url | |
| const robot = await robotService.getRobotById(id) | |
| this.setState({ currentId: id, robot }) | |
| } | |
| async componentDidUpdate(prevProps) { | |
| if (prevProps && prevProps.match.params.id !== this.state.currentId) { | |
| const id = this.props.match.params.id; // params -> from url | |
| const robot = await robotService.getRobotById(id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| useEffect(() => { | |
| function handleStatusChange(status) { | |
| setIsOnline(status.isOnline); | |
| } | |
| ChatAPI.subscribeToBuddyStatus(props.buddy.id, handleStatusChange); | |
| return () => { | |
| ChatAPI.unsubscribeFromBuddyStatus(props.buddy.id, handleStatusChange); | |
| }; | |
| }, [props.buddy.id]); // Only re-subscribe if props.buddy.id changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| function Example() { | |
| const [count, setCount] = useState(0); | |
| useEffect(() => { | |
| document.title = `You clicked ${count} times, dear balak`; | |
| } | |
| return ( | |
| <div> | |
| <p> You clicked {count} times, dear balak. </p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| useEffect(() => { | |
| document.title = `You clicked ${count} times`; | |
| }, [count]); // Only re-run the effect if count changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function LoginForm() { | |
| const [user, setUser] = useState({ username: '', password:'' }); | |
| const updateUserField = e => { | |
| setUser({ ...user, [e.target.name]: e.target.value }); | |
| }; | |
| return ( | |
| <form> | |
| <label> | |
| Username: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| function Example() { | |
| const [count, setCount] = useState(0); | |
| return ( | |
| <div> | |
| <p> You clicked {count} times, dear balak. </p> | |
| <button onClick={() => setCount(count + 1)}> | |
| Click me | |
| </button> | |
| </div> |
NewerOlder