Skip to content

Instantly share code, notes, and snippets.

View davidgilbertson's full-sized avatar

David Gilbertson davidgilbertson

  • Sydney, Australia
View GitHub Profile
const List = (props: {
items: any[];
renderItem: (item: any) => React.ReactNode;
}) => (
<>{props.items.map(props.renderItem)}</>
);
<List
items={notProducts}
renderItem={notAProduct => (
<p>
{notAProduct.name}: {notAProduct.code}
</p>
)}
/>
<List
items={products}
renderItem={product => (
<p>
{product.name}: ${product.proice}
</p>
)}
/>
const hasLocalStorage = typeof window !== 'undefined' && !!window.localStorage;
export const set = (key: string, data: any) => {
if (!hasLocalStorage) return undefined;
try {
const string = typeof data === 'string' ? data : JSON.stringify(data);
return localStorage.setItem(key, string);
} catch (err) {
+import { store } from 'react-recollect'; // New line

export function toggleTodo(index) {
+  store.todos[index].completed = !store.todos[index].completed; // New line
  
-  return { type: TOGGLE_TODO, index }
}
import React from 'react';
import { collect } from 'react-recollect';
const App = ({ store }) => {
const { thatThing } = store.site.page.meta.data;
const { anotherThing } = store.ui;
const { aThirdThing } = store.maps.schemas.plans.operations;
return /* ... */
};
import { store } from 'react-recollect';
const loadTodos = async () => {
const userId = store.user.id;
store.todos = await fetch(`/api/todos/${userId}`).then((resp) => resp.json());
};
const loadTodos = () => async (dispatch, getState) => {
const userId = getState().user.id;
const todos = await fetch(`/api/todos/${userId}`).then((resp) => resp.json());
dispatch({
type: 'LOADED_TODOS',
data: todos,
});
};
console.assert(
JSON.stringify(recollectStore.todos) === JSON.stringify(reduxStore.getState().todos),
'The two stores should match'
);
import { store } from 'react-recollect'; // New line
export function toggleTodo(index) {
store.todos[index].completed = !store.todos[index].completed; // New line
return { type: TOGGLE_TODO, index }
}