File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 11mod element;
22mod macro_import;
3+ mod use_effect;
34mod use_ref;
45mod use_state;
56
67pub use element:: * ;
8+ pub use use_effect:: * ;
79pub use use_ref:: * ;
810pub use use_state:: * ;
911
Original file line number Diff line number Diff line change 1+ use wasm_bindgen:: prelude:: * ;
2+
3+ crate :: macro_import:: wasm_bindgen_react! {
4+ /// `React.useEffect(effect, dependencies)`
5+ ///
6+ /// # Safety
7+ ///
8+ /// `effect` closure will be passed to js runtime
9+ /// and called ( or never called ) asynchronously by React.
10+ ///
11+ /// As [`wasm_bindgen`](https://rustwasm.github.io/docs/wasm-bindgen/reference/passing-rust-closures-to-js.html) describes,
12+ ///
13+ /// > Once a Closure is dropped, it will deallocate its internal memory
14+ /// > and invalidate the corresponding JavaScript function
15+ /// > so that any further attempts to invoke it raise an exception.
16+ ///
17+ /// Rust compiler can only ensure this closure is not dropped before `use_effect` returned,
18+ /// so it's up to you to make sure the closure lived longer enough
19+ /// to be valid in the component life time.
20+ ///
21+ /// Thus, this function is marked `unsafe` as a warning.
22+ #[ wasm_bindgen( js_namespace = React , js_name = useEffect) ]
23+ pub unsafe fn use_effect( effect: & Closure <dyn FnMut ( ) >, dependencies: Option <Box <[ JsValue ] >>) ;
24+
25+ #[ wasm_bindgen( js_namespace = React , js_name = useEffect) ]
26+ pub unsafe fn use_effect_with_clean(
27+ effect: & Closure <dyn FnMut ( ) -> JsValue >,
28+ dependencies: Option <Box <[ JsValue ] >>,
29+ ) ;
30+ }
You can’t perform that action at this time.
0 commit comments