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 App() { | |
const [count, setCount] = useState(0); | |
function handleClick(){ | |
return (setTimeout(() => { | |
alert("You clicked on: " + count); | |
}, 3000)); | |
} |
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 App() { | |
const [count, setCount] = useState(0); | |
const latestValue = useRef(count); | |
const handleClick = () => { | |
setTimeout(() => { | |
alert(`count is: ${latestValue.current}`); | |
}, 3000); | |
}; | |
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
test('Clicking on + increments the number', () => { | |
// using enzyme | |
const wrapper = mount(<Count />); | |
expect(wrapper.state('count')).toBe(0); | |
wrapper.instance().incrementCount(); | |
expect(wrapper.state('count')).toBe(1); | |
}); |
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
test('Clicking on + increments the number', () => { | |
// using React Testing Library | |
render(<Count />); | |
expect(screen.getByText('Total')).toBeInTheDocument(); | |
userEvent.click(screen.getByText('Click')); | |
expect(screen.queryByText('1')).toBeInTheDocument(); | |
}); |
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 from 'react'; | |
import { renderToString } from 'react-dom/server'; | |
function App() { | |
const html = renderToString(<>Hey there!</>); | |
return <div dangerouslySetInnerHTML={{__html: html}}></div>; | |
}; | |
export default App; |
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 from 'react'; | |
import ReactDOMServer from 'react-dom/server'; | |
import express from 'express'; | |
const app = express(); | |
app.use('/static', express.static('public')); | |
const App = (props) => { | |
return <div>Hello {props.name}</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
@Freeze | |
class Person {} | |
function Freeze(constructor: Function) { | |
Object.freeze(constructor); | |
Object.freeze(constructor.prototype); | |
} | |
console.log(Object.isFrozen(Person)); // true |
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 class Person { | |
@Emoji() | |
name = 'Sean'; | |
} | |
// Property Decorator | |
function Emoji() { | |
return function(target: Object, key: string | symbol) { | |
let val = target[key]; | |
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 class Person { | |
names = []; | |
@Confirmable('Are you sure?') | |
@Confirmable('Are you super, super sure? There is no going back!') | |
addName(name) { | |
this.names.push(name); | |
} | |
} |
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
enum WeekDay { | |
MONDAY = 0, | |
TUESDAY = 1, | |
WEDNESDAY = 2, | |
THURSDAY = 3, | |
FRIDAY = 4, | |
SATURDAY = 5, | |
SUNDAY = 6 | |
} |