Last active
March 7, 2019 16:18
-
-
Save trueadm/4a938f2ffb5ae65d9384ede7bee4310f to your computer and use it in GitHub Desktop.
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
// "counter.react" | |
import {format} from 'externalLib'; | |
state { | |
// acts like default state | |
counter = 0; | |
} | |
props { | |
// acts like default props | |
maxCounter = 10; | |
} | |
view { | |
<div className="container"> | |
<button onClick={increment}>{format(state.counter)}</button> | |
</div> | |
} | |
function increment(e) { | |
setState(state => { | |
if (state.counter < props.maxCounter) { | |
return { | |
counter: state.counter + 1 | |
}; | |
} | |
return null; | |
}); | |
} |
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
// "counter.react" | |
import {format} from 'externalLib'; | |
state { | |
// acts like default state | |
counter = 0; | |
} | |
props { | |
// acts like default props | |
maxCounter = 10; | |
} | |
export function render() { | |
return ( | |
<div className="container"> | |
<button onClick={increment}>{format(state.counter)}</button> | |
</div> | |
); | |
} | |
function increment(e) { | |
setState(state => { | |
if (state.counter < props.maxCounter) { | |
return { | |
counter: state.counter + 1 | |
}; | |
} | |
return null; | |
}); | |
} |
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
// "counter.react" | |
import {format} from 'externalLib'; | |
state { | |
// acts like default state | |
counter = 0; | |
} | |
props { | |
// acts like default props | |
maxCounter = 10; | |
} | |
events { | |
function increment(e) { | |
setState(state => { | |
if (state.counter < props.maxCounter) { | |
return { | |
counter: state.counter + 1 | |
}; | |
} | |
return null; | |
}); | |
} | |
} | |
<style> | |
.container { | |
color: red; | |
background: {props.backgroundColor} | |
} | |
</style> | |
<view> | |
<div className="container"> | |
<button onClick={increment}>{format(state.counter)}</button> | |
</div> | |
</view> |
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
// "counter.react" | |
import {format} from 'externalLib'; | |
state { | |
// acts like default state | |
counter = 0; | |
} | |
props { | |
// acts like default props | |
maxCounter = 10; | |
} | |
reducer { | |
increment: state => ({ | |
counter: state.counter + 1, | |
}) | |
} | |
view { | |
<div className="container"> | |
<button onClick={increment}>{format(state.counter)}</button> | |
</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
// "counter.react" | |
import {format} from 'externalLib'; | |
import {setState} from "react"; | |
let counter = 0; | |
function increment(props, e) { | |
setState(() => { | |
if (counter < props.maxCounter) { | |
counter++ | |
} | |
}); | |
} | |
export function render(props) { | |
return ( | |
<div className="container"> | |
<button onClick={increment}>{format(counter)}</button> | |
</div> | |
); | |
} | |
export const defaultProps = { | |
maxCounter: 10, | |
}; |
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
// "counter.react" | |
import {format} from 'externalLib'; | |
import {setState} from 'react'; | |
component { | |
let counter = 0; | |
function increment(props, e) { | |
setState(() => { | |
if (counter < props.maxCounter) { | |
counter++ | |
} | |
}); | |
} | |
export function render(props) { | |
return ( | |
<div className="container"> | |
<button onClick={increment}>{format(counter)}</button> | |
</div> | |
); | |
} | |
export const defaultProps = { | |
maxCounter: 10, | |
}; | |
} |
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
// "counter.js" | |
import {format} from 'externalLib'; | |
import {createStatefulComponent} from 'react'; | |
export defaut createStatefulComponent(({render, defaultProps, setState}) => { | |
let counter = 0; | |
function increment(props, e) { | |
setState(() => { | |
if (counter < props.maxCounter) { | |
counter++ | |
} | |
}); | |
} | |
render((props) => { | |
return ( | |
<div className="container"> | |
<button onClick={increment}>{format(counter)}</button> | |
</div> | |
); | |
}); | |
defaultProps({ | |
maxCounter: 10, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment