Skip to content

Allow to have slices return selectors state and derivate values #413

Closed
@yeion7

Description

@yeion7

First at all, thank for redux-toolkit ❤️

One thing that seems a lot of boilerplate for me in redux is to have a lot of selector and all the boilerplate with reselect to access the state or create derivate values

Here's a rough initial API proposal:

const todosSlice = createSlice({
  name: "todos",
  initialState: { todos: [], filter: "ALL" },
  reducers: { ... },
  derived: {
    total: state => state.todos.length,
    currentTodos: state => state.todos.filter(todo => todo.status === state.filter)
  }
})

And inside of the component

function Todos(props) {
  const { total,  currentTodos, filter} = useSelector(todosSlice.selectors)
  return ...
}

Maybe it couldn’t be possible but in this way I think redux-toolkit could help to reduce a lot of code

What are everyone's thoughts?

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