Skip to content

Instantly share code, notes, and snippets.

@carlrip
carlrip / Store.ts
Created February 3, 2019 14:25
React Redux Reducer with TypeScript
const peopleReducer: Reducer<IPeopleState, PeopleActions> = (
state = initialPeopleState,
action,
) => {
switch (action.type) {
case 'GettingPeople': {
return {
...state,
loading: true,
};
@carlrip
carlrip / Store.ts
Created February 3, 2019 14:39
React Redux Store with TypeScript
export function configureStore(): Store<IAppState> {
const store = createStore(rootReducer, undefined, applyMiddleware(thunk));
return store;
}
@carlrip
carlrip / App.tsx
Last active February 5, 2019 03:52
React Redux Component with TypeScript
interface IProps {
getPeople: () => Promise<IGotPeopleAction>;
people: IPerson[];
peopleLoading: boolean;
postPerson: (person: IPostPerson) => Promise<IPostedPersonAction>;
personPosting: boolean;
}
const App: FC<IProps> = ({
getPeople,
@carlrip
carlrip / terminal
Created February 9, 2019 15:51
Style components installation with TypeScript types
npm install styled-components
npm install @types/styled-components --save-dev
@carlrip
carlrip / App.tsx
Last active February 9, 2019 16:21
Playing with styled components - unstyled list
...
<div>
<ul>
{posts.map(({ id, title, body }) => (
<li key={id}>
<div>
<span>{title}</span>
<span>{body}</span>
</div>
@carlrip
carlrip / App.tsx
Last active February 10, 2019 09:32
Playing with styled components - basic component
import styled from 'styled-components';
const Container = styled.div`
width: 400px;
margin: 30px auto;
`;
const App = () => (
<Container>
<ul>
@carlrip
carlrip / Styles.ts
Created February 9, 2019 16:16
Playing with styled components - global style variable
// Grays
export const gray1 = '#383737';
export const gray2 = '#565555';
export const gray3 = '#857c81';
export const gray4 = '#b9b9b9';
export const gray5 = '#e0dddd';
// Colors
export const primary1 = '#6ca583';
export const accent1 = '#9b8dab';
@carlrip
carlrip / App.tsx
Last active February 10, 2019 09:32
Playing with styled components - variables
...
import { fontFamily, fontSize, gray2 } from './Styles';
const Container = styled.div`
width: 400px;
margin: 30px auto;
font-family: ${fontFamily};
font-size: ${fontSize};
color: ${gray2};
`;
@carlrip
carlrip / App.tsx
Last active February 10, 2019 09:32
Playing with styled components - nesting
const Container = styled.div`
width: 400px;
margin: 30px auto;
font-family: ${fontFamily};
font-size: ${fontSize};
color: ${gray2};
ul {
list-style: none;
padding: 0px 20px;
background-color: #fff;
@carlrip
carlrip / App.tsx
Created February 10, 2019 09:27
Playing with styled components - separating
const Container = styled.div`
width: 400px;
margin: 30px auto;
font-family: ${fontFamily};
font-size: ${fontSize};
color: ${gray2};
`;
const List = styled.ul`
list-style: none;