https://github.com/rannie/ochooks
An Objective-C Hooks Like React Hooks
https://github.com/rannie/ochooks
hooks objective-c reacthooks
Last synced: about 2 months ago
JSON representation
An Objective-C Hooks Like React Hooks
- Host: GitHub
- URL: https://github.com/rannie/ochooks
- Owner: Rannie
- License: mit
- Created: 2018-12-04T09:03:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-04T09:28:36.000Z (almost 7 years ago)
- Last Synced: 2025-02-21T19:27:00.307Z (8 months ago)
- Topics: hooks, objective-c, reacthooks
- Language: Objective-C
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OCHooks
An Objective-C Hooks Like React Hooks## Usage
#### State
* Create
```Objective-C
OCHooks *count = [OCHooks useState:@(0)];
[count addChangeHandler:^(id newValue, id oldValue) {
NSLog(@"change count old: %@, new: %@", oldValue, newValue);
}];
self.count = count;
```* Change Value
```Objective-C
self.count.value = @(1);
```#### Effect
* Create
```Objective-C
OCHooks *effectHooks = [OCHooks useEffect];
[effectHooks appear:^{
NSLog(@"appear");
}];
[effectHooks disappear:^{
NSLog(@"disappear");
}];
```#### Install and Uninstall
```
// after create Hooks
[self OCH_installHooks:@[count, effectHooks]];
// clean up like -dealloc
[self OCH_uninstallHooks];
```## Lisence
**MIT**