Skip to content

Instantly share code, notes, and snippets.

View vzaidman's full-sized avatar

Vitali Zaidman vzaidman

View GitHub Profile
const Main = React.memo(({onClick, style, children, items}) => {
const content = getContent({items});
return (
<div style={style} onClick={onClick}>
{content}
{children}
</div>
);
})
@vzaidman
vzaidman / useRefWithCallback.jsx
Last active December 22, 2023 17:13
useRefWithCallback
// the hook
function useRefWithCallback(onMount, onUnmount) {
const nodeRef = useRef(null);
const setRef = useCallback(node => {
if (nodeRef.current) {
onUnmount(nodeRef.current);
}
nodeRef.current = node;
@vzaidman
vzaidman / currencyFormatList.json
Created November 23, 2015 13:52
LCID-to-currency-format-mapping as appears in sharepoint currency field
{
"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)",
import user from './user'
describe('user', () => {
// before each test
beforeEach(() => {
// spy on the "isValid" function on the "user" object
jest.spyOn(user, 'isValid');
})
class Child {
...
execute(arg) { ... }
...
}
class Father {
constructor() {
this.child = new Child()
}
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
@vzaidman
vzaidman / useStateRef.jsx
Last active January 17, 2021 14:34
useStateRef
// 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
@vzaidman
vzaidman / useState-as-a-ref.jsx
Last active January 14, 2021 19:08
useState-as-a-ref
const [node, setRef] = useState(null);
useEffect(() => {
if (!node) {
console.log('unmounted!');
return null;
}
console.log('mounted');
@vzaidman
vzaidman / babel.config.js
Created November 24, 2020 11:14
How to test two React versions
module.exports = require('../babel.config')
@vzaidman
vzaidman / jest.config.js
Created November 24, 2020 11:10
How to test two React versions
module.exports = {
...require('../jest.config'),
rootDir: '..',
cacheDirectory: '.cache/jest-cache-react-16',
moduleDirectories: [
'<rootDir>/test-react-16/node_modules',
'node_modules'
]
}