This file contains 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 Main = React.memo(({onClick, style, children, items}) => { | |
const content = getContent({items}); | |
return ( | |
<div style={style} onClick={onClick}> | |
{content} | |
{children} | |
</div> | |
); | |
}) |
This file contains 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
// the hook | |
function useRefWithCallback(onMount, onUnmount) { | |
const nodeRef = useRef(null); | |
const setRef = useCallback(node => { | |
if (nodeRef.current) { | |
onUnmount(nodeRef.current); | |
} | |
nodeRef.current = node; |
This file contains 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
{ | |
"1164": "؋123,456.00 (Afghanistan)", | |
"1052": "123,456.00 Lek (Albania)", | |
"5121": "د.ج. 123,456.00 (Algeria)", | |
"11274": "$ 123,456.00 (Argentina)", | |
"1067": "123,456.00 ֏ (Armenia)", | |
"3081": "$123,456.00 (Australia)", | |
"3079": "123,456.00 € (Austria)", | |
"1068": "123,456.00 man. (Azerbaijan)", | |
"2092": "123,456.00 ман. (Azerbaijan)", |
This file contains 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 user from './user' | |
describe('user', () => { | |
// before each test | |
beforeEach(() => { | |
// spy on the "isValid" function on the "user" object | |
jest.spyOn(user, 'isValid'); | |
}) | |
This file contains 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 Child { | |
... | |
execute(arg) { ... } | |
... | |
} | |
class Father { | |
constructor() { | |
this.child = new Child() | |
} |
This file contains 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
describe('My First Cypress Test', function() { | |
it("Gets, types and asserts", function() { | |
cy.visit('https://example.cypress.io') | |
cy.contains('type').click() | |
// Should be on a new URL which includes '/commands/actions' | |
cy.url().should('include', '/commands/actions') | |
// Get an input, type into it and verify that the value has been updated |
This file contains 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
// the hook | |
function useStateRef(processNode) { | |
const [node, setNode] = useState(null); | |
const setRef = useCallback(newNode => { | |
setNode(processNode(newNode)); | |
}, [processNode]); | |
return [node, setRef]; | |
} | |
// how it's used |
This file contains 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 [node, setRef] = useState(null); | |
useEffect(() => { | |
if (!node) { | |
console.log('unmounted!'); | |
return null; | |
} | |
console.log('mounted'); | |
This file contains 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
module.exports = require('../babel.config') |
This file contains 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
module.exports = { | |
...require('../jest.config'), | |
rootDir: '..', | |
cacheDirectory: '.cache/jest-cache-react-16', | |
moduleDirectories: [ | |
'<rootDir>/test-react-16/node_modules', | |
'node_modules' | |
] | |
} |
NewerOlder