All Projects → pankod → react-hooks-example

pankod / react-hooks-example

Licence: other
React Hooks Example

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to react-hooks-example

use-metamask
a custom React Hook to manage Metamask in Ethereum ĐApp projects
Stars: ✭ 131 (+523.81%)
Mutual labels:  react-hooks
max-todos
A basic Todo app developed in React.
Stars: ✭ 19 (-9.52%)
Mutual labels:  react-hooks
react
🎣 React hooks & components on top of ocean.js
Stars: ✭ 27 (+28.57%)
Mutual labels:  react-hooks
minesweeper
💣Minesweeper game written with React
Stars: ✭ 18 (-14.29%)
Mutual labels:  react-hooks
Eorg
new version: https://github.com/SoftMaple/Editor
Stars: ✭ 27 (+28.57%)
Mutual labels:  react-hooks
todo
🤖 🚀 I created Todo. Hope you like it and enjoy the open source
Stars: ✭ 16 (-23.81%)
Mutual labels:  react-hooks
use-react-redux-context
Alternative ReactRedux.connect by useContext for performance
Stars: ✭ 44 (+109.52%)
Mutual labels:  react-hooks
react-sendbird-messenger
ReactJS (React-router-dom v6 + Antdesign + Firebase + Sendbird + Sentry) codebase containing real world examples (CRUD, auth, advanced patterns, etc).
Stars: ✭ 39 (+85.71%)
Mutual labels:  react-hooks
react-vite-admin
This Starter utilizes React, Recoil, React Query, React Hooks, Typescript, Axios And Vite. 全新技术栈的后台管理系统
Stars: ✭ 90 (+328.57%)
Mutual labels:  react-hooks
react-abac
Attribute Based Access Control for React
Stars: ✭ 54 (+157.14%)
Mutual labels:  react-hooks
rbac-react-redux-aspnetcore
A starter template for creating JWT token from ASP.NET Core API project and applying that JWT token authentication on React application
Stars: ✭ 54 (+157.14%)
Mutual labels:  react-hooks
formalizer
React hooks based form validation made for humans.
Stars: ✭ 12 (-42.86%)
Mutual labels:  react-hooks
react-daterange-picker
A react date range picker to using @material-ui. Live Demo: https://flippingbitss.github.io/react-daterange-picker/
Stars: ✭ 85 (+304.76%)
Mutual labels:  react-hooks
react-sample-projects
The goal of this project is to provide a set of simple samples, providing and step by step guide to start working with React.
Stars: ✭ 30 (+42.86%)
Mutual labels:  react-hooks
MERN-BUS-APP
This is a MFRP (My first Real Project) assigned to me during my internship at Cognizant. Made with MERN Stack technology.
Stars: ✭ 92 (+338.1%)
Mutual labels:  react-hooks
epee-react-admin
🗡简洁、高效、易扩展的 React 快速开发模板,基于布局设计,纯 Hooks 开发,包含中后台应用常用功能
Stars: ✭ 87 (+314.29%)
Mutual labels:  react-hooks
reason-hooks-lib
A set of reusable ReasonReact hooks.
Stars: ✭ 31 (+47.62%)
Mutual labels:  react-hooks
react-hooks-file-upload
React Hooks File Upload example with Progress Bar using Axios, Bootstrap
Stars: ✭ 30 (+42.86%)
Mutual labels:  react-hooks
react-europe-2019
Slides and demo app from my keynote
Stars: ✭ 29 (+38.1%)
Mutual labels:  react-hooks
react-native-value-picker
Cross-Platform iOS(ish) style picker for react native.
Stars: ✭ 18 (-14.29%)
Mutual labels:  react-hooks
React Hooks Example

Hooks

import React, { useState, useRef, useEffect } from "react";

export function Countdown(props) {
	const intervalRef = useRef();
	const [countDown, setCountdown] = useState(props.countDown);

	useEffect(() => {
		const id = setInterval(function () {
			setCountdown(countDown => countDown - 1);
		}, 1000);

		intervalRef.current = id;

		return () => {
			clearInterval(intervalRef.current);
		}
	}, []);

	return (
		<div>
			<p>{countDown} seconds</p>
			<button onClick={() => setCountdown(countDown + 10)}>
				Add 10 seconds
      		</button>
		</div>
	);
}

Class

import React from "react";

export class CountdownClass extends React.Component {
	interval = 0;
	constructor(props) {
		super(props);
		this.state = {
			countDown: props.countDown
		};
	}

	componentDidMount() {
		this.setup();
	}

	componentWillUnmount() {
		clearInterval(this.interval);
	}

	render() {
		return (
			<div>
				<p>{this.state.countDown} seconds</p>
				<button onClick={() => this.setState({ countDown: this.state.countDown + 10 })}>
					Add 10 seconds
      			</button>
			</div>
		);
	}

	setup() {
		this.interval = setInterval(function () {
			this.countdown();
		}.bind(this), 1000)
	}

	countdown() {
		this.setState({ countDown: this.state.countDown - 1 });
	}
}

Custom Hooks

import React, { useState } from "react";

import useInterval from './useInterval';

export function CountdownWithUseInterval(props) {
	const [countDown, setCountdown] = useState(props.countDown);

	useInterval(function () {
		setCountdown(countDown => countDown - 1);
	}, 1000);

	return (
		<div>
			<p>{countDown} seconds</p>
			<button onClick={() => setCountdown(countDown + 10)}>
				Add 10 seconds
      		</button>
		</div>
	);
}

Learn More

You can learn more in the Introducing Hooks .

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].