Skip to content

Document Zustand store action naming conventions in dev docs #289

@coderabbitai

Description

@coderabbitai

Background

When implementing Zustand store actions, we follow these naming conventions:

  • Use setX for actions that simply change the value of a state
  • Use updateX for actions that do more than simply changing a value (e.g., perform additional logic, make API calls, update multiple states)

Task

Add this naming convention to the development documentation to ensure consistent implementation across the codebase.

Example

// Example of a simple setter (use 'set' prefix)
setPageNum: (newPageNum: number) => {
  set({pageNum: newPageNum});
}

// Example of a complex action (use 'update' prefix)
updateIsPrettified: (newIsPrettified: boolean) => {
  // Has additional logic beyond just setting the value
  if (newIsPrettified === get().isPrettified) {
    return;
  }
  set({isPrettified: newIsPrettified});
  
  // Performs other actions...
  setUiState(UI_STATE.FAST_LOADING);
  // ...
}

References

Related PR: #286

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions