Is it possible to use provideState() to set up multiple reducers as root reducers?

Angular and ngrx are currently at version 16.0.0.

StoreModule.forRoot({
      app: appReducer,
      anotherFeatureName: anotherFeatureReducer
    }),
    EffectsModule.forRoot([
      AppEffects,
      AnotherEffects
    ]),

I have begun the migration process to a standalone Angular application. As part of this transition, I need to remove StoreModule and EffectsModule from app.module.ts. However, I am struggling to find the correct way to provide multiple reducers and their corresponding effects using standalone APIs.

I have attempted various approaches, but none have yielded the expected results. The state remains undefined when the application tries to access it.

Answer №1

1. Start by ensuring that you have imported the necessary NgRx modules along with your reducers and effects.

import { provideState } from '@ngrx/store';
import { provideEffects } from '@ngrx/effects';
import { appReducer } from './app.reducer';
import { anotherFeatureReducer } from './another-feature.reducer';
import { AppEffects } from './app.effects';
import { AnotherEffects } from './another.effects';

2. Within your app module, utilize the provideState() function to supply your root reducers.

import { provideState } from '@ngrx/store';

@NgModule({
  imports: [
    //Omit StoreModule.forRoot()
    //Omit EffectsModule.forRoot()
    // Utilize provideState() to offer your root reducers
    provideState({
      app: appReducer,
      anotherFeatureName: anotherFeatureReducer,
    }),
  ],
})
export class AppModule {}

3. In the same manner, apply the provideEffects() function to provide your root effects.

import { provideEffects } from '@ngrx/effects';

@NgModule({
  imports: [
    //Omit StoreModule.forRoot()
    //Omit EffectsModule.forRoot()
    // Utilize provideState() for your root reducers
    provideState({
      app: appReducer,
      anotherFeatureName: anotherFeatureReducer,
    }),

    // Implement provideEffects() for your root effects
    provideEffects([AppEffects, AnotherEffects]),
  ],
})
export class AppModule {}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps should I follow to create a versatile table component?

Can you please advise me on how to create generic data in a table using Typescript? I encountered this error message while trying to useTable({ at line data The error states: Type 'T[]' is not assignable to type 'readonly object[]'. ...

Accessing and transferring files through Angular with a .NET Core API

I am working on an Angular application that utilizes a .Net Core API to handle image uploads and retrieval. Here is the code for my Angular service: import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angul ...

Styling Angular parent and child components: Best practices for consistent design

I'm currently expanding my skills in Angular 18, even though I am already familiar with React. In my project, I have a rather extensive HTML file that I would like to break down into smaller components. Here is a simplified and minified example: <u ...

Insert an icon on the designated date within the NGB Calendar

I have integrated the ng-bootstrap datepicker to show a calendar in my app with an inline view. However, I am facing an issue where the calendar does not display the current day icon as shown here. https://i.sstatic.net/bySjX.png Can anyone offer a solut ...

What is the reason for Google Chrome extension popup HTML automatically adding background.js and content.js files?

While using webpack 5 to bundle my Google Chrome extension, I encountered an issue with the output popup HTML. It seems to include references to background.js and content.js even though I did not specify these references anywhere in the configuration file. ...

Iterate through the Ionic3/Angular4 object using a loop

I've been attempting to cycle through some content. While I tried a few solutions from StackOverflow, none seem to be effective in my case. Here is the JSON data I am working with: { "-KmdNgomUUnfV8fkzne_":{ "name":"Abastecimento" }, ...

Position the div beneath another div using the display:grid property

I can't seem to figure out how to position a div below another div using display:grid. The div is appearing on top instead of below. The "app-bm-payment-card-item" is actually a custom Angular component. Here's the HTML file: //div wrapper < ...

Using the React UseEffect Hook allows for value updates to occur within the hook itself, but not within the main

I am currently utilizing a font-picker-react package to display fonts using the Google Font API. Whenever a new font is chosen from the dropdown, my goal is to update a field value accordingly. While the 'value' updates correctly within the ...

The generic parameter is extending a type but is being used in a contravariant position, causing TypeScript to struggle to unify it

When developing my functions, I aim to provide flexibility for consumers to use a wider type. However, I encounter issues when the type is used in a contravariant position and TypeScript raises complaints. Here is the simplified code snippet: function wra ...

Is there a way to extend RouteComponentProps in order to accommodate additional props?

I am encountering an issue with this piece of typescript code in a React render props component. The error is related to the fact that RouteComponentProps does not contain a prop called 'component'. class Auth extends Component<RouteComponent ...

Storing and retrieving information in ag-grid using Angular

I have created two grids, Grid_A and Grid_B, both containing a column labeled "Activite". When the user edits cells in the "Activite" column in Grid_A, those same values are displayed in the corresponding column in Grid_B. This functionality is achieved th ...

A guide to seamlessly uploading files to s3 using nextjs, node, and typescript

I've been struggling to successfully upload a basic image to s3 using ts/nextjs/node. Despite having all the necessary credentials and code in place, I'm still unable to get it working. Can someone please provide clear instructions on how to achi ...

Angular 2: Issue with Table not Being Updated

https://i.stack.imgur.com/qLDUZ.png The UsersList component opens a new page upon clicking the table. https://i.stack.imgur.com/WwqIX.png After changing and saving user values, the updated value is not immediately reflected in the grid for the first tim ...

How can we exclude fields from JSON.stringify in type-graphql entities?

Utilizing https://github.com/MichalLytek/type-graphql for crafting our graphql schema has posed a challenge. When we serialize the TypeScript entity object, it does not adhere to the field annotations in our GQL entities, resulting in unwanted data leakage ...

A guide to resolving the error "Cannot read properties of undefined (reading 'length')" while implementing pagination with react, Material-UI, and TypeScript

As I work on my code, my goal is to display a limited number of cards per page based on the data stored in a JSON file. I anticipated that clicking on the ">" or "<" icon would navigate to the next or previous page respectively, updating the displaye ...

What is the process for incorporating a .scss file into an Angular 2 component?

Hey there! I've got a component styled in scss and I'm trying to apply it. I've already completed the installation: npm install node-sass sass-loader raw-loader --save-dev Within my component, I've included: @Component ({ selector ...

Troubleshooting: Why is Angular's Material Autocomplete failing to function with post requests?

I have been working on a project using Angular Material autocomplete, but I have encountered an issue where the autocomplete feature is not functioning properly. Despite my efforts to debug and identify the problem, I seem to have exhausted all possible so ...

Is there a distinction between Entity[] and array<Entity> in TypeScript?

Everything in the title, for example people: Person[]; people: Array<Person>; What sets them apart? Is there a preferred approach? Note: I couldn't find any guidance on this and I've encountered both in code. ...

There seems to be an issue with the functionality of Angular's updateValueAndValidity() method

I am facing an issue with a simple form setup: <form [formGroup]="form" (ngSubmit)="onSubmit()" novalidate> <input type="radio" id="enabled" formControlName="enabled" [value]="true" ...

Issues with the ionViewDidLoad() function?

Having some trouble implementing Email Authentication in my project. The method ionViewDidLoad is not being recognized. I also tried using the method ionViewWillLoad() but that didn't work either. Any ideas on what might be causing this issue? Here&a ...