I'm working with Angular 8 and NgRx 8, is it possible create an action with optional payload? I'm trying to do something like:
export const MyAction = createAction('[Action ] MyAction', props<{ prop?: string }>());
but unfortunately doesn't work. Could you help me?
Based on this post there is an optional payload definition.
Example:
export const FetchPlayersAction = createAction(
'[Players.List] FETCH_PLAYERS',
(payload: ListingOptions = {}) => payload, // defined optional payload
);
Based on your example, you can set a default value, and then it's optional:
export const MyAction = createAction(
'[Action ] MyAction',
(prop: string = 'My default value') => ({ prop })
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With