Skip to content

Instantly share code, notes, and snippets.

View carpben's full-sized avatar

Ben Carp carpben

  • Tel Aviv, Israel
View GitHub Profile
function requestTodos() {
return axios.get("/todos"); // or a different request function that throws on an error
}
// A query provider is a
function Todos() {
const { data, status, error } = useQuery("todos", requestTodos);
if (status === "loading") {
return <span>Loading...</span>;
/** Original */
import DR from "general/types"
interface IScrollLockProps {
accountForScrollbars?: boolean
touchScrollTarget?: HTMLElement
}
declare module "react-scrolllock" {
@carpben
carpben / useFocus.ts
Created August 10, 2019 04:52
useFocus.ts
export const useFocus = () => {
const htmlElRef = useRef<HTMLElement>()
const setFocus = () => {
const currentEl = htmlElRef.current
currentEl && currentEl.focus()
}
return [setFocus, htmlElRef] as const
}
const scrollToRef = (ref) => window.scrollTo(0, ref.current.offsetTop) // General scroll to element function
const ReadyToScroll = () => {
const myRef = useRef(null) // Hook to ref object
return (<div ref={myRef}>I wanna be seen</div>) // Attach ref object to a dom element
}
// To scroll run `scrollToRef(myRef)`. Examples:
// To scroll on mount add above the return statement:
useEffect(() => {
const Comp = ({items}) => (
<div className=”list”>
{
items.length?
<ul>
{
items.map( item=> <li>{item.name}</li>) )
</ul>
: <p>No Items found</p>
}
@carpben
carpben / ImageArea.tsx
Created November 22, 2018 08:54
ImageArea - render method restuctured
import * as React from'react';
import {Component} from'react';
import styled, { css } from 'react-emotion';
import { StyledComponentProps } from "../../types"
import IconW from "../Wrappers/IconW";
import { faChevronRight } from "@fortawesome/pro-regular-svg-icons";
import { faChevronLeft } from "@fortawesome/pro-regular-svg-icons";
interface Props {
import * as React from'react';
import {Component} from'react';
import styled, { css } from 'react-emotion';
import { StyledComponentProps } from "../../types"
import IconW from "../Wrappers/IconW";
import { faChevronRight } from "@fortawesome/pro-regular-svg-icons";
import { faChevronLeft } from "@fortawesome/pro-regular-svg-icons";
interface Props {
import sys
print "Welcome to the Fizzbuzz Game!"
# defining n.
# first option command line argument. command line can have: 0 argument (no n), 1 arguments (n) or more than 1 arguments (mistake/error)
# In case of 1 arguments, the second argument is n. otherwise we will ask user to provide input (n).
#possible problems: argument or input should be an integer in type string. If that is not the case than we have a problem.
# we are instructed to handel error.
# it will arise when we try to convert from type string to type integer.