add must use to several hooks

This commit is contained in:
Evan Almloff committed 2023-10-14 12:08:54 -05:00
1 parent 04f83e1e92
commit 3bf6d2d7cf
21 files changed
+25

No files matched your search

+2
View File
@@ -37,6 +37,7 @@ use std::{
/// }
/// }
/// ```
#[must_use]
pub fn use_tracked_state<T: 'static>(cx: &ScopeState, init: impl FnOnce() -> T) -> &Tracked<T> {
cx.use_hook(|| {
let init = init();
@@ -160,6 +161,7 @@ impl<I> Drop for Tracker<I> {
}
}
#[must_use = "Consider using the `use_effect` hook to rerun an effect whenever the tracked state changes if you don't need the result of the computation"]
pub fn use_selector<I: 'static, O: Clone + PartialEq + 'static>(
cx: &ScopeState,
tracked: &Tracked<I>,
+2
View File
@@ -24,6 +24,8 @@ macro_rules! use_callback {
)
};
}
#[must_use]
pub fn use_callback<T, R, F>(cx: &ScopeState, make: impl FnOnce() -> R) -> impl FnMut(T) + '_
where
R: FnMut(T) -> F + 'static,
+1
View File
@@ -3,6 +3,7 @@ use dioxus_core::ScopeState;
/// Consume some context in the tree, providing a sharable handle to the value
///
/// Does not regenerate the value if the value is changed at the parent.
#[must_use]
pub fn use_context<T: 'static + Clone>(cx: &ScopeState) -> Option<&T> {
cx.use_hook(|| cx.consume_context::<T>()).as_ref()
}
+1
View File
@@ -79,6 +79,7 @@ where
/// Get a handle to a coroutine higher in the tree
///
/// See the docs for [`use_coroutine`] for more details.
#[must_use]
pub fn use_coroutine_handle<M: 'static>(cx: &ScopeState) -> Option<&Coroutine<M>> {
cx.use_hook(|| cx.consume_context::<Coroutine<M>>())
.as_ref()
+1
View File
@@ -17,6 +17,7 @@ use crate::{use_state, UseState};
/// will be canceled before the new one is started.
///
/// - dependencies: a tuple of references to values that are PartialEq + Clone
#[must_use = "Consider using `cx.spawn` to run a future without reading its value"]
pub fn use_future<T, F, D>(
cx: &ScopeState,
dependencies: D,
+1
View File
@@ -28,6 +28,7 @@ use crate::UseFutureDep;
/// render!(Calculator { number: 0 })
/// }
/// ```
#[must_use = "Consider using `use_effect` to run rerun a callback when dependencies change"]
pub fn use_memo<T, D>(cx: &ScopeState, dependencies: D, callback: impl FnOnce(D::Out) -> T) -> &T
where
T: 'static,
+1
View File
@@ -110,6 +110,7 @@ use std::{
/// }
/// })
/// ```
#[must_use]
pub fn use_ref<T: 'static>(cx: &ScopeState, initialize_refcell: impl FnOnce() -> T) -> &UseRef<T> {
let hook = cx.use_hook(|| UseRef {
update: cx.schedule_update(),
+1
View File
@@ -158,6 +158,7 @@ impl<T> ProvidedStateInner<T> {
/// Any time a component calls `write`, every consumer of the state will be notified - excluding the provider.
///
/// Right now, there is not a distinction between read-only and write-only, so every consumer will be notified.
#[must_use]
pub fn use_shared_state<T: 'static>(cx: &ScopeState) -> Option<&UseSharedState<T>> {
let state_owner: &mut Option<UseSharedStateOwner<T>> = &mut *cx.use_hook(move || {
let scope_id = cx.scope_id();
+1
View File
@@ -30,6 +30,7 @@ use std::{
/// ))
/// }
/// ```
#[must_use]
pub fn use_state<T: 'static>(
cx: &ScopeState,
initial_state_fn: impl FnOnce() -> T,