Create a new react hook called prestate

This issue has been created since 2022-09-16.

I want to add a new react hook called prestate hook this hook will allow accessing previous values that the user assigned
I'm going to work on it if someone is interested in it then please leave a comment

DIWAKARKASHYAP wrote this answer on 2022-09-17

i am interested to work on it but i have no experience in opensource

amirqasemi74 wrote this answer on 2022-09-19

what do you mean by pre-state. when you are going to set state, as you know setState accepts a function as value which react pass pre value of state as argument to it and it returns new state. there you have pre-state. if you need more, please explain more with the api you mean

matvp91 wrote this answer on 2022-09-19

Wouldn't this work, assuming I'm not missing the point.

function usePrevState(value) {
  const ref = useRef();
  useEffect(() => {
    ref.current = value;
  }, [value]);
  return ref.current;
}

const [value, setValue] = useState(1);
const prevValue = usePrevState(value);
varwasabi wrote this answer on 2022-09-21

usePrevious is a well known custom hook and I assume it is what you're asking for. I'm not sure there's a place for it in core though as it has a specific use case and not something that would be used in every application unlike those already part of react core.

madhusudhan123-star wrote this answer on 2022-09-27

Even I am also interested but have zero experience in open-source. varwasabi commented use previous and also alternative options.

umerprogramm wrote this answer on 2022-09-27

Hello Everyone!
Thanks for making your interest in it. So a lot of guys are interested, But they not understanding what I'm actually trying to say.
prestate Hook is just not going to be Hook that contains the previous values but it also contains some cool methods Like:

  • Binary Search
  • sorting Arrays
  • Reduce the repeated elements from the array
    And much more. (If you have an idea feel free to leave a comment I will definitely put that on my list)

I will soon put a code example that helps to visualize what I'm trying to say.

More Details About Repo
Owner Name facebook
Repo Name react
Full Name facebook/react
Language JavaScript
Created Date 2013-05-24
Updated Date 2022-09-26
Star Count 195293
Watcher Count 6655
Fork Count 40426
Issue Count 1113

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
[v22.1.x] test: NodesDecommissioningTest.test_decommissioning_working_node test failure 0 2022-05-11 2022-07-22
The Miner is broken 2 2021-11-07 2022-01-15
minercheck 2 2021-11-07 2022-01-15
Racket-mode support uses unavailable function 0 2022-01-10 2022-09-07
Document how to use Aseprite with KorGE 1 2021-10-17 2022-08-23
Update ASE asesprite to support 1.3 : TileMap/TileSet 1 2021-11-07 2022-08-23
[Feature Suggestion] Config file with keys that are automatically collapsed 1 2021-07-14 2022-09-13
Crash on startup when selecting OpenGL Renderer before closing MelonDS 0 2022-02-08 2022-09-22
BrushSize dinamically changing 2 2020-08-07 2022-09-05
The auto-formatter spreads large array literals over lines in a really frustrating manner 2 2021-11-21 2022-07-20
chart/otomi default values.yaml are outdated. 2 2021-09-02 2022-09-24
Configurable size on MaxMessageSize in WebSocketAdapter.cs 4 2020-07-29 2022-09-10
Question: possible to load widgets remotely? 0 2021-08-09 2022-09-24
Options menu doesn't work when wallet warning is disabled 1 2021-10-21 2022-09-12
How to view data in YJS roomwise in a read only mode? 1 2021-06-10 2022-08-17
domain https errore for flutter web 4 2022-01-17 2022-09-10
Increasing number of clients during FL simulation 1 2022-05-09 2022-08-10
Chapter Request: Indore, India 3 2019-09-02 2022-08-21
Can't build latest master version using Android Studio 0 2021-06-13 2022-08-21
proxmark3 easy 512mb Can't use on rfidtools 5 2022-05-04 2022-09-04
Pop all screens, whether the tab is already selected or not 4 2021-04-11 2022-09-10
Пометка того что платеж был сделан через СБП 1 2021-06-23 2022-08-14
Отсутствует поле Token 8 2021-07-24 2022-09-06
hard-coded string breaks on single file components with typescript having "<" 0 2021-08-25 2022-07-29
How to Start Ratchet without Command ? 0 2021-06-07 2022-09-13
How to pass request throw the nginx? 1 2021-07-22 2022-09-13
Use swift-argument-parser 1 2021-10-30 2022-08-26
[Issue]: Startup Loop - System.FormatException: Dashes are in the wrong position for GUID parsing. 1 2022-03-11 2022-09-20
[Issue]: Transcoding and DirectPlay issues 1 2022-03-10 2022-09-12
RuntimeError fetching golang dependencies - fixed updating golang version to latest 2 2022-08-23 2022-09-21
Fusio on Swoole 1 2021-11-26 2021-12-30
Photos are not displayed on the map 9 2022-02-04 2022-09-23
optional values for MPTCP_CMD_SUB_CREATE in netlink_pm_mptcp_org.c 4 2021-05-08 2022-08-24
NSG on Deep100m dataset 1 2022-01-20 2022-08-14
Implement verifyAggregateCertificateSignature function of Certificate 0 2021-10-18 2022-08-15
Distributed mode minio failed to configure TLS/HTTPS 1 2022-03-01 2022-02-22
Lagom 1.6.0-M4 5 2019-07-11 2021-12-04
Alpha build working on Intel AC9560 0 2021-11-02 2022-09-26
Add a list of provided library dependencies 0 2017-02-17 2022-09-19
Remove `Template` page from page index 1 2021-10-19 2022-09-25
Remove those lint errors 0 2021-12-08 2022-07-23
Add support for taxonomization of packagings 0 2022-02-10 2022-07-23
[unclear documentation] Are incomplete type annotations allowed under --disallow-untyped-defs? 0 2022-04-28 2022-08-24
PostRun is an awkward fit for CLI output 2 2018-08-10 2022-08-14
Feature request: Drop old lhma_ tables 4 2015-03-19 2022-09-10
Dropdown selection is not cleared when removing value set using `setValue()` 1 2021-10-14 2022-09-10
function with the name "new" messes with folding and formatting 13 2021-11-09 2022-07-19
anaconda will not launch 0 2021-08-05 2022-08-17
Book page 62 refers to solr 8.3.1 but the earlier examples refer to solr v8.6.2 1 2021-03-09 2022-09-15
Due to seasonal holidays, many of our members are taking time off. Please expect delayed responses until early January. 3 2021-11-30 2022-09-09