Our Best Practices for Writing React Components
import { string, object } from 'prop-types'
this.setState(prevState => ({ expanded: !prevState.expanded }))
state = { count: this.props.initialCount };| #include <stdexcept> | |
| #include <iostream> | |
| #include <initializer_list> | |
| template <typename T> | |
| class Vector | |
| { | |
| static constexpr std::size_t min_capacity = 8; | |
| public: |
| interface ColorSelectionOptions { | |
| signal?: AbortSignal | |
| } | |
| interface ColorSelectionResult { | |
| sRGBHex: string | |
| } | |
| interface EyeDropper { | |
| open: (options?: ColorSelectionOptions) => Promise<ColorSelectionResult> |
| def plotDist(topplesize, xmin, xmax): | |
| fit = powerlaw.Fit( | |
| data = np.array(topplesize), | |
| xmin = xmin, | |
| xmax = xmax | |
| ) | |
| x, y = fit.pdf(linear_bins=True) | |
| ind = y>0 | |
| y = y[ind] | |
| x = x[:-1] |
| package com.berci; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| record Tuple<T, U>(T one, U other){} | |
| @FunctionalInterface | |
| interface Combine<T> { | |
| T method(T left, T right); |
| interface Balanced { | |
| boolean check(String input); | |
| } | |
| interface Checkout { | |
| int total(Cart c, List<Discount> dc); | |
| } |
| function maybe<T>(gen: () => Generator<T, any, any>): T | null { | |
| const next = gen(); | |
| let last = undefined; | |
| while (true) { | |
| const { value, done } = next.next(last); | |
| if (done) { | |
| return value; | |
| } | |
| if (value == null) { | |
| return null; |
| import inspect | |
| def with_checks(checks): | |
| def wrapper(func): | |
| def wrapped(*args, **kwargs): | |
| bound_args = inspect.signature(func).bind(*args, **kwargs) | |
| errors = list() | |
| for check in checks: | |
| decorator_params = inspect.signature(check).parameters.keys() | |
| matching_params = [(sym, bound_args.arguments[sym]) for sym in decorator_params if sym in bound_args.arguments.keys()] | |
| if len(matching_params) > 0: |