Skip to content

Instantly share code, notes, and snippets.

View andyrichardson's full-sized avatar

Andy Richardson andyrichardson

View GitHub Profile
#!/bin/bash
dnf update -y
dnf groupinstall "Development Tools"
dnf install perl kernel-devel kernel-headers dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
dnf install docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
describe('on user click', () => {
const props = {
  friends,
  onUserChange: jest.fn(),
  };
it('calls on user change', () => {
  const wrapper = shallow(<FriendsList {…props} />);
  wrapper.find('FriendItem[value="Paul"]').simulate('click'); 
  expect(onUserChange).toBeCalledWith('Paul');
describe('on mount', () => {
it('renders friends list', () => {
  expect(shallow(<FriendsList friends={friends} />)).toMatchSnapshot()
  });
 
  it('renders "no friends found"', () => {
  expect(shallow(<FriendsList />)).toMatchSnapshot()
  });
});
// Trigger event
const handleClick = useCallback(() => fetch(url), []);
// Trigger change to render output
const handleClick = useCallback(() => setNewState(s => s+1), []);
const MyComponent = ({ loading }) => (
if (loading) {
return <Spinner />;
}
return <MainContent />;
);
// Context file
export const MyContext = createContext(null);
// Provider abstraction file
import { MyContext } from './context';
export const ProviderAbstraction = ({ children }) => {
const [modalState, setModalState] = useState(false);
return (
@andyrichardson
andyrichardson / Forcing Inference of React component generics.md
Last active May 9, 2019 09:57
Quick and dirty way to force inference on a specific component property with typescript.

Quick and dirty way to force inference on a specific component property with typescript.

interface Props<T, D extends T> {
  ground: T;                  // Value of T is inferred here
  collection: D[];            // Value of T is used here but is of generic D
  function: (arg: D) => void; // And here
}

// Here we use the GroundedProps interface in our component