-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Labels
Description
Info
difficulty: easy
title: usePrevious
type: question
template: react
tags: reactQuestion
Implement a custom React hook called usePrevious that stores the previous value of a given state or prop.
Template
template.react.md
import { useState } from "react";
import { usePrevious } from "./usePrevious";
export default function App() {
const [count, setCount] = useState(0);
const prevCount = usePrevious(count);
return (
<div>
<p>Current: {count}</p>
<p>Previous: {prevCount}</p>
<button onClick={() => setCount(c => c + 1)}>Increment</button>
</div>
);
}export function usePrevious(value) {
}