Skip to content

Logging when set_state is called and no changes occur #565

Closed
@Archmonger

Description

@Archmonger

Current Situation

Currently, there exists circumstances where set_state can be called and nothing will occur. For example, modifying a mutable class (such as a dataclass)

@dataclass
class MyState:
   value: str = ""

@idom.component
def my_component():
   state, set_state = idom.hooks.use_state(MyState())

   async def on_click(event):
      state.value = "dog"
      set_state(state)
      # This does not trigger a re-render. Need to use copy.copy(state).

   return button( {"onClick"=on_click}, ... )

Proposed Changes

Notify the user if set_state was called and no re-render was queued.

Implementation Details

When in IDOM_DEBUG_MODE...
Show either logging.warning or logging.info when set_state is called but a re-render was not trigged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-2-moderateShould be resolved on a reasonable timeline.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions