Kebab file names

This commit is contained in:
Angelos Chalaris
2023-04-27 22:01:10 +03:00
parent f39deb9522
commit f1ce423d01
78 changed files with 0 additions and 0 deletions

35
snippets/use-update.md Normal file
View File

@ -0,0 +1,35 @@
---
title: React useUpdate hook
tags: components,reducer
author: chalarangelo
cover: lavender-shelf
firstSeen: 2021-09-24T05:00:00-04:00
---
Forces the component to re-render when called.
- Use the `useReducer()` hook that creates a new object every time it's updated and return its dispatch.
```jsx
const useUpdate = () => {
const [, update] = React.useReducer(() => ({}));
return update;
};
```
```jsx
const MyApp = () => {
const update = useUpdate();
return (
<>
<div>Time: {Date.now()}</div>
<button onClick={update}>Update</button>
</>
);
};
ReactDOM.createRoot(document.getElementById('root')).render(
<MyApp />
);
```