Skip to content

Instantly share code, notes, and snippets.

😎
learning

C. T. Lin chentsulin

😎
learning
Block or report user

Report or block chentsulin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Counter.js
const Counter = ({ defaultValue }) => {
const [count, setCount] = useState(defaultValue);
const handlePlusOne = () => {
setCount(count + 1);
}
return (
<>
<div>{count}</div>
@chentsulin
chentsulin / Counter.js
Created Nov 5, 2018
counter powerplug
View Counter.js
import { Counter as PCounter } from 'react-powerplug'
const Counter = ({ defaultValue }) => {
return (
<PCounter initial={defaultValue}>
{({ count, inc }) => (
<>
<div>{count}</div>
<button onClick={inc}>+</button>
@chentsulin
chentsulin / Counter.js
Last active Nov 6, 2018
counter class
View Counter.js
class Counter {
state = {
value: this.props.defaultValue
};
handlePlusOne = () => {
this.setState(() => ({ value: this.state.value + 1 }));
};
render() {
View Counter.js
const Counter = ({ defaultValue }) => {
return (
<>
<div>{defaultValue}</div>
<button>+</button>
</>
);
};
@chentsulin
chentsulin / App.js
Last active Nov 5, 2018
hooks-useEffect
View App.js
const App = ({ userId }) => {
useEffect(() => {
subscribe(userId);
return () => {
unsubscribe(userId);
};
}, [userId]);
// ...
};
View App.js
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);
}
@chentsulin
chentsulin / App.js
Last active Nov 6, 2018
renderProps-Context
View App.js
const App = () => {
return (
<ThemeContext.Consumer>
{theme => (
<LocaleContext.Consumer>
{locale => (
<div className={theme}>
{locale}
</div>
)}
@chentsulin
chentsulin / App.js
Created Nov 5, 2018
hooks-useContext
View App.js
const App = () => {
const theme = useContext(ThemeContext);
const locale = useContext(LocaleContext);
return (
<div className={theme}>
{locale}
</div>
);
};
@chentsulin
chentsulin / App.js
Last active Nov 5, 2018
hooks-useState
View App.js
const App = () => {
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const handleNameChange = event => {
setName(event.target.value);
};
const handleEmailChange = event => {
setEmail(event.target.value);
};
View imagemap.js
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,
You can’t perform that action at this time.