Skip to content

Instantly share code, notes, and snippets.

View pushkar100's full-sized avatar

Pushkar DK pushkar100

  • PayPal
  • Bangalore
  • 09:37 (UTC +05:30)
View GitHub Profile
import React, { useState } from "react";
const ProductSearchFilter = ({
products = [],
colors = [],
sizes = [],
onSearch = () => {}
}) => {
const [product, setProduct] = useState(null);
const [selectedColors, setSelectedColors] = useState([]);
import React, { useState, useCallback } from "react";
const readStyle = { backgroundColor: "grey" };
const unreadStyle = { backgroundColor: "white" };
const useReadStatusUpdater = (hasRead, onReset) => {
const [read, setRead] = useState(hasRead || false);
const resetRead = useCallback(() => {
setRead(hasRead);
import React, { useState, useCallback } from "react";
const readStyle = { backgroundColor: "grey" };
const unreadStyle = { backgroundColor: "white" };
const EmailsListItem = ({ hasRead, onReadStatusChange }) => {
const [read, setRead] = useState(hasRead || false);
const resetRead = useCallback(() => {
setRead(hasRead);
// Handle side effects during a reset!
import React, { useState, useCallback } from "react";
const readStyle = { backgroundColor: "grey" };
const unreadStyle = { backgroundColor: "white" };
const EmailsListItem = ({ hasRead }) => {
const [read, setRead] = useState(hasRead || false);
const resetRead = useCallback(() => setRead(hasRead), [hasRead]);
const style = read ? readStyle : unreadStyle;
const logClick = () => console.log("button clicked");
const callAll = (...fns) => (...args) => fns.forEach((fn) => fn(...args));
export const buttonPropsGetter = ({ customOnClick, ...props }) => ({
onClick: callAll(logClick, customOnClick), // Extensible
tabIndex: 0,
role: "button",
"aria-disabled": false,
text: "Button",
const buttonAriaPropCollection = {
tabIndex: 0,
role: "button",
"aria-disabled": false
};
const Button = ({ text, onClick, tabIndex, role, 'aria-disabled': ariaDisabled }) => {
return (
<button onClick={onClick} tabIndex={tabIndex} role={role} aria-disabled={ariaDisabled}>
{text}
const Button = ({ text, onClick, tabIndex, ariaDisabled }) => {
return (
<button
onClick={onClick}
tabIndex={tabIndex}
role="button"
aria-disabled={ariaDisabled}
>
{text}
</button>
import Menu from "./Menu";
import MenuButton from "./MenuButton";
import MenuItem from "./MenuItem";
export default () => (
<Menu hideButtons>
<MenuButton text="Exit" action={() => console.log("Exiting")} />
<MenuButton text="Settings" action={() => console.log("settings")} />
<MenuItem text="News" />
<MenuItem text="Serials" />
import React from "react";
const MenuItem = ({ text }) => <div key={text}>{text}</div>;
export default MenuItem;
import React, { useContext } from "react";
import { MenuContext } from "./Menu";
const MenuButton = ({ text, action }) => {
const { hideButtons } = useContext(MenuContext);
if (hideButtons) {
return null;
}