Valtio/V2/Migration Recipe

1.0.0Last update Aug 30, 2024
by@manishjha-04

This recipe provides a collection of codemods to help you migrate your codebase to Valtio v2. These codemods are designed to streamline the transition process by automating common code transformations due to behavioral changes in Valtio v2.

Codemods Included

The following codemods are included in this recipe:

  1. Proxy Function Behavior Update
    Updates instances of proxy(obj) to use deepClone to ensure objects are deeply copied as in Valtio v1. This adjustment is necessary due to the change from a pure function in v1 to an impure function in v2 that modifies the original object.

  2. useSnapshot Behavior Adaptation
    Modifies the usage of useSnapshot() to be compatible with recent changes for better optimization with useMemo and the upcoming React compiler. This includes wrapping snapshot data with use() to ensure compatibility and performance.

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now