feat: mvoe away from compound context
This commit is contained in:
1 parent
bfdcb20437
commit
a2c7d17b05
103 files changed
+309
-293
No files matched your search
@@ -36,7 +36,7 @@ uses the same memoization on top of the use_context API.
|
||||
|
||||
Here's a fully-functional todo app using the use_map API:
|
||||
```rust
|
||||
static TodoList: FC<()> = |cx| {
|
||||
static TodoList: FC<()> = |cx, props|{
|
||||
let todos = use_map(cx, || HashMap::new());
|
||||
let input = use_ref(|| None);
|
||||
|
||||
|
||||
@@ -33,6 +33,6 @@ impl<T> Clone for UseRef<'_, T> {
|
||||
}
|
||||
impl<T> Copy for UseRef<'_, T> {}
|
||||
|
||||
pub fn use_ref<P, T: 'static>(cx: Context<P>, f: impl FnOnce() -> T) -> UseRef<T> {
|
||||
pub fn use_ref<T: 'static>(cx: Context, f: impl FnOnce() -> T) -> UseRef<T> {
|
||||
cx.use_hook(|_| RefCell::new(f()), |f| UseRef { inner: f }, |_| {})
|
||||
}
|
||||
@@ -35,7 +35,7 @@ use std::{
|
||||
///
|
||||
/// Usage:
|
||||
/// ```ignore
|
||||
/// const Example: FC<()> = |cx| {
|
||||
/// const Example: FC<()> = |cx, props|{
|
||||
/// let counter = use_state(cx, || 0);
|
||||
/// let increment = |_| counter += 1;
|
||||
/// let decrement = |_| counter += 1;
|
||||
@@ -49,8 +49,8 @@ use std::{
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T, P>(
|
||||
cx: Context<'a, P>,
|
||||
pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T>(
|
||||
cx: Context<'a>,
|
||||
initial_state_fn: F,
|
||||
) -> UseState<'a, T> {
|
||||
cx.use_hook(
|
||||
|
||||
Reference in new issue
Block a user