Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo()
do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.
Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:
- Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
- Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory
/* | |
* Handling Errors using async/await | |
* Has to be used inside an async function | |
*/ | |
try { | |
const response = await axios.get('https://your.site/api/v1/bla/ble/bli'); | |
// Success 🎉 | |
console.log(response); | |
} catch (error) { | |
// Error 😨 |
import { forEachObjIndexed } from "ramda"; | |
import * as React from "react"; | |
import { | |
Animated, | |
ScrollView, | |
View, | |
ViewStyle, | |
LayoutChangeEvent, | |
NativeScrollEvent, | |
} from "react-native"; |
- Location - The location of the application. Usually just a URL, but the location can contain multiple pieces of information that can be used by an app
- pathname - The "file/directory" portion of the URL, like
invoices/123
- search - The stuff after
?
in a URL like/assignments?showGrades=1
. - query - A parsed version of search, usually an object but not a standard browser feature.
- hash - The
#
portion of the URL. This is not available to servers inrequest.url
so its client only. By default it means which part of the page the user should be scrolled to, but developers use it for various things. - state - Object associated with a location. Think of it like a hidden URL query. It's state you want to keep with a specific location, but you don't want it to be visible in the URL.
- pathname - The "file/directory" portion of the URL, like
type QueryResult<TTransformedData> = | |
| { type: "success"; data: TTransformedData } | |
| { type: "error"; errors: readonly GraphQLError[] }; | |
type ParentEvents<TData, TId extends string = "dataLoader"> = | |
| { type: "dataStream.NEW_DATA"; data: TData; id: TId } | |
| { type: "dataStream.ERROR"; id: TId }; | |
export function createDataStream< | |
TObservableFactory extends (...args: $YesReallyAny[]) => Observable<QueryResult<$YesReallyAny>>, |
export default function createCrudHooks({ | |
baseKey, | |
indexFn, | |
singleFn, | |
createFn, | |
updateFn, | |
deleteFn, | |
}) { | |
const useIndex = (config) => useQuery([baseKey], indexFn, config) | |
const useSingle = (id, config) => |
-- Collision-resistant ids optimized for horizontal scaling and performance, for PL/PgSQL. | |
-- Based on https://github.com/ericelliott/cuid | |
-- Version 1.0.0 | |
-- Usage: SELECT cuid(); | |
-- BEGIN CONFIG --- | |
-- Put a unique host ID (int) here per server instance. | |
-- Once set, this value should not be changed. |
import * as SystemUI from 'expo-system-ui'; | |
import * as React from 'react'; | |
import { Appearance, AppState, AppStateStatus, ColorSchemeName, ColorValue } from 'react-native'; | |
type ThemedColorValue = { light: ColorValue, dark: ColorValue }; | |
type Props = { backgroundColor: ColorValue | ThemedColorValue } | |
const propsStack: Props[] = []; |
Personally I've never liked how tools like Remix or NextJS have mapped a nested file system to routes. Simple things like "I want to put this component in its own file" become annoying tasks.
I've always been a fan of "flatter" file systems, my files often look like this:
/App/