Skip to main content
Version: Next

From 0.19.0 to Next

Dependencies as first hook argument and use_effect_with

  • Replace use_effect_with_deps with new use_effect_with
  • use_effect_with, use_callback, use_memo now take dependencies as their first argument

Automated refactor

With the help of Here are commands that can do the refactoring for you.

sg --pattern 'use_effect_with_deps($CALLBACK,$$$DEPENDENCIES)' --rewrite 'use_effect_with($$$DEPENDENCIES, $CALLBACK)' -l rs -i
sg --pattern 'use_effect_with($DEPENDENCIES,,$$$CALLBACK)' --rewrite 'use_effect_with($DEPENDENCIES,$$$CALLBACK)' -l rs -i

sg --pattern 'use_callback($CALLBACK,$$$DEPENDENCIES)' --rewrite 'use_callback($$$DEPENDENCIES, $CALLBACK)' -l rs -i
sg --pattern 'use_callback($DEPENDENCIES,,$$$CALLBACK)' --rewrite 'use_callback($DEPENDENCIES,$$$CALLBACK)' -l rs -i

sg --pattern 'use_memo($CALLBACK,$$$DEPENDENCIES)' --rewrite 'use_memo($$$DEPENDENCIES, $CALLBACK)' -l rs -i
sg --pattern 'use_memo($DEPENDENCIES,,$$$CALLBACK)' --rewrite 'use_memo($DEPENDENCIES,$$$CALLBACK)' -l rs -i


This will enable more ergonomic use of hooks, consider:

impl SomeLargeStruct {
fn id(&self) -> u32; // Only need to use the id as cache key
let some_dep: SomeLargeStruct = todo!();

let id =; // Have to extract it in advance, some_dep is moved already in the second argument
use_effect_with_dep(move |_| { todo!(); drop(some_dep); }, id);