Skip to content

Instantly share code, notes, and snippets.

const btnArr = [
{id: 1,text: "Hover Me"},
{id: 2,text: "I am Magnetic"},
{id: 3,text: "Read More"},
]
const App = () => {
return (
<div className="App">
{btnArr.map((item) => (
<MagneticButton key={item.id} item={item} />
//HTML
<title>Split Effect </title>
//CSS
body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
}
import { useState, useEffect } from "react";
import axios from "axios";
/**
* useApi Hook used for fetching data
* Fetching can be stopped by using the skip argument.
* That is usefull, when we want to gather some data before fetching(like some ID)
*/
import React from 'react';
import { ListItemProps } from './ListItem';
export type ListComponent<T = {}> = React.FC<ListItemProps<T>>;
export interface SelectProps<T>{
items: T[];
darkMode: boolean;
loading: boolean;
//Sample Array Data
const sampleData = [
{ name: "Bill", score: 15 },
{ name: "Jane", score: 18 },
{ name: "Fred", score: 10 }
]
<List data = {sampleData} onRowClick={row => console.log(row)} />
//*Example
//Where ( listOfItems ) is an array of items
<List items={listOfItems} dir="vertical">
{(listOfItem) => (
<dl>
<dt>Name</dt>
<dd>{listOfItem.name}</dd>
<dt>Created</dt>
<dd>{listOfItem.since}</dd>
@DarkoTrpevski
DarkoTrpevski / types.ts
Created December 23, 2020 14:46
React useForm hook v3
export interface FormInput {
value: any;
onChange: any;
error: string;
}
export interface FormError {
[key: string]: string;
}
export interface ValidationOption {
required?: string;
@DarkoTrpevski
DarkoTrpevski / useForm.tsx
Created December 23, 2020 14:45
React useForm hook v2
import React, { useState, FormEvent, ChangeEvent } from 'react'
export interface IUseFormOptions {
initialState?: { [key: string]: any }
onSuccessSubmit: (inputs: { [key: string]: any }) => void
}
const useForm = (opts: IUseFormOptions) => {
@DarkoTrpevski
DarkoTrpevski / useForm.tsx
Created December 23, 2020 14:43
React useForm hook v1
import { useState } from "react";
export const useFormFields = (initialState: any) => {
const [values, setValues] = useState(initialState);
return [
values,
setValues,
(e: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLSelectElement>) => {
const { type, name } = e.target;