Skip to content

Instantly share code, notes, and snippets.

@yunghoy
Last active January 12, 2020 16:11
Show Gist options
  • Save yunghoy/0f925b55d549dd9fcc0f961ef0e9d5d1 to your computer and use it in GitHub Desktop.
Save yunghoy/0f925b55d549dd9fcc0f961ef0e9d5d1 to your computer and use it in GitHub Desktop.
React
const TimerComponent = (props) => {
const [time, setTime] = useState((new Date()).toLocaleString('en'));
setInterval(() => {
setTime((new Date()).toLocaleString('en'));
}, 1000);
};
const NameComponent = (props) => {
const [name, setName] = useState("Peter");
return (
<h1>Name: {name}
<button onClick={(event) => {setName("Nope")} }> TEST_BUTTON </button>
</h1>
);
};
https://www.robinwieruch.de/react-function-component
interface RootProp {}
interface RootStates {
name: string
}
class Root extends React.Component<RootProps, RootState> {
construct(props: RootProps) {
super(props);
const initState: RootState = {name: "Peter"};
this.setState(initState);
}
render {
return (
<h1>Name: {name}
<button onClick={(event) => {this.setState(name: "Nope")} }> TEST_BUTTON </button>
</h1>
);
}
}
const spread = (props: any) => {
return (
<h1 {...props}>Spread Test</h1>
);
};
ReactDOM.render(
<Root2 test="123" test2="234"/>,
document.getElementById('root')
);
// <h1 test="123" test2="234">Spread Test</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment