Skip to content

Instantly share code, notes, and snippets.

@RomainBitard
RomainBitard / App.tsx
Created January 25, 2024 06:46
Redux MVP without npm install
// idea from https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367
import './App.css';
import React, {useState} from "react";
interface ActionType {
type: string;
}
function CounterReducer(state = {value: 0}, action: ActionType = {type: ""}) {
switch (action.type) {
@RomainBitard
RomainBitard / OtherPage.test.tsx
Last active December 31, 2023 15:04
Dependency injection using React Context
// taken from https://www.youtube.com/watch?v=MSpDAuDPqNw
import OtherPage from "./OtherPage";
import {fireEvent, render, screen, waitFor} from "@testing-library/react";
import {DataMuseApiContext} from "./SomeLayout";
describe('the page', () => {
it('should do stuff', async () => {
const logSpy = jest.spyOn(console, 'log') // never do that :p
render(<DataMuseApiContext.Provider value={{
async getWordsSoundingLike(word: string) {
// npm install tslint-immutable --save-dev
// tslint.json
{
"extends": ["tslint-immutable"],
"rules": {
// Recommended built-in rules
"no-var-keyword": true,
"no-parameter-reassignment": true,
"typedef": [true, "call-signature"],