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
const Counter = ({ defaultValue }) => { | |
const [count, setCount] = useState(defaultValue); | |
const handlePlusOne = () => { | |
setCount(count + 1); | |
} | |
return ( | |
<> | |
<div>{count}</div> |
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 { Counter as PCounter } from 'react-powerplug' | |
const Counter = ({ defaultValue }) => { | |
return ( | |
<PCounter initial={defaultValue}> | |
{({ count, inc }) => ( | |
<> | |
<div>{count}</div> | |
<button onClick={inc}>+</button> |
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
class Counter { | |
state = { | |
value: this.props.defaultValue | |
}; | |
handlePlusOne = () => { | |
this.setState(() => ({ value: this.state.value + 1 })); | |
}; | |
render() { |
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
const Counter = ({ defaultValue }) => { | |
return ( | |
<> | |
<div>{defaultValue}</div> | |
<button>+</button> | |
</> | |
); | |
}; |
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
const App = ({ userId }) => { | |
useEffect(() => { | |
subscribe(userId); | |
return () => { | |
unsubscribe(userId); | |
}; | |
}, [userId]); | |
// ... | |
}; |
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
class App extends Component { | |
componentDidMount() { | |
this.subscribe(this.props.userId); | |
} | |
componentDidUpdate(prevProps) { | |
if (this.props.userId !== prevProps.userId) { | |
this.unsubscribe(this.props.userId); | |
this.subscribe(this.props.userId); | |
} |
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
const App = () => { | |
return ( | |
<ThemeContext.Consumer> | |
{theme => ( | |
<LocaleContext.Consumer> | |
{locale => ( | |
<div className={theme}> | |
{locale} | |
</div> | |
)} |
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
const App = () => { | |
const theme = useContext(ThemeContext); | |
const locale = useContext(LocaleContext); | |
return ( | |
<div className={theme}> | |
{locale} | |
</div> | |
); | |
}; |
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
const App = () => { | |
const [name, setName] = useState(''); | |
const [email, setEmail] = useState(''); | |
const handleNameChange = event => { | |
setName(event.target.value); | |
}; | |
const handleEmailChange = event => { | |
setEmail(event.target.value); | |
}; |
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
client.sendImagemap(userId, 'Re: [問卦] 齊柏林導演的故事給了我們什麼啟示?', { | |
baseWidth: 1040, | |
baseHeight: 720, | |
baseUrl: 'https://our.image.com/server/path', | |
actions: [ | |
{ | |
type: 'uri', | |
linkUri: 'https://www.ptt.cc/bbs/Gossiping/M.1497100764.A.C81.html', | |
area: { | |
x: 0, |
NewerOlder