I have an action defined as such in the creator:
export const actionCreators = {
submitlink: (url: string) => <SubmitLinkAction>{ type: 'SUBMIT_LINK' }
}
in the component calling it:
public render() {
return <div>
<div>{this.props.url}</div>
<button onClick={() =>
{
this.props.submitlink("google.com");
}}>submit</button>
</div>
}
So I'm trying to figure out how in the reducer function I can grab thea rgument passed in? This is what the reducer looks like:
export const reducer: Reducer<SubmitLinkState> = (state: SubmitLinkState, action: KnownAction) => {...}
As an aside if this is not the correct workflow what should I do? The end goal is to have a text box and the submit buttonw ill send the contents of that text box to the reducer.
You can pass the url as an action parameter like
export const actionCreators = {
submitlink: (url: string) => <SubmitLinkAction>{ type: 'SUBMIT_LINK', url}
}
and then in the reducer access it as action.url
export const reducer: Reducer<SubmitLinkState> = (state: SubmitLinkState, action: KnownAction) => {
...
console.log(action.url);
}
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