An Objective-C Hooks Like React Hooks
- Create
OCHooks *count = [OCHooks useState:@(0)];
[count addChangeHandler:^(id newValue, id oldValue) {
NSLog(@"change count old: %@, new: %@", oldValue, newValue);
}];
self.count = count;
- Change Value
self.count.value = @(1);
- Create
OCHooks *effectHooks = [OCHooks useEffect];
[effectHooks appear:^{
NSLog(@"appear");
}];
[effectHooks disappear:^{
NSLog(@"disappear");
}];
// after create Hooks
[self OCH_installHooks:@[count, effectHooks]];
// clean up like -dealloc
[self OCH_uninstallHooks];
MIT