This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState } from 'react' | |
| export const useForm = (initialValue, middlewareFn) => { | |
| const [data, setData] = useState(initialValue); | |
| const middleware = | |
| typeof middlewareFn === "function" ? middlewareFn : data => data; | |
| /* | |
| - onChange(event) | |
| uses the event target's `name` and `value` (or `checked` if the type of the target is "checkbox") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState, useContext, useEffect } from 'react' | |
| import { StoreContext } from '../contexts/store.context' | |
| export const useRedux = (selector = state => state, mapDispatch = {}) => { | |
| const store = useContext(StoreContext) | |
| if (!store) { | |
| throw new Error( | |
| `Store not found. Wrap your application within a StoreProvider and pass it the appropriate store prop.` | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from 'react' | |
| import { Store, Unsubscribe, Dispatch } from 'redux' | |
| const stateContext = React.createContext() | |
| const { Provider, Consumer } = stateContext | |
| export interface StateProviderProps<T> { | |
| store: Store<T> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let search = function(db, tableName, query) { | |
| let table = db.table(tableName) | |
| let clause = Object.keys(query).reduce( (r, n) => { | |
| if (typeof query[n] === "undefined" || query[n] === null) return r; | |
| let where = !r ? table.where(n) : r.or(n) | |
| if (query[n] && query[n].constructor === String) { | |
| return where.startsWith(query[n]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { Component } from 'react'; | |
| let Sort = Sortable => class extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| items: [] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { Component } from 'react'; | |
| let Filter = Filterable => class extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| items: props.items | |
| }; |