question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript useDispatch 'expected 0-1 arguments, but got 2'

See original GitHub issue

I read through the similar recent issue from slugs99, but still can’t get Typescript to work.

I’m trying to use the new useDispatch syntax which takes two arguments, like so: const dispatchFilters = useDispatch(setFilter, 'filters');

I’m using the latest reactn (2.1.4). I went into types/provider.d.ts and it does appear that useDispatch is typed to take two arguments so I’m not sure what is wrong.

Perhaps something in my global.d.ts file is wrong? I’m using something similar to the default template.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CharlesStovercommented, Jul 11, 2019

I’m going to close this since it was taken up in the Discord and now lacks context. If you still need help or have a clear Issue/reproduction, feel free to re-open or make a new issue with the context needed to resolve it. 😄

0reactions
CharlesStovercommented, Jun 21, 2019

If you don’t use addReducer but put your Reducer in your global.d.ts file, TypeScript won’t complain at compile time, but it shouldn’t do anything at runtime, because that function won’t exist on the global state and isn’t actually being returned by useDispatch.

There is a Discord channel dedicated to ReactN, linked at the top and bottom of the README. I can’t guarantee that I am available to respond immediately, but I am responding in my free time. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with expected 0 arguments, but got 1 in Redux Toolkit
So your getNames reducer is going to get state where you're trying to get name, you're missing the action (2nd parameter), and you're...
Read more >
Expected 0 arguments, but got 1. : r/reduxjs - Reddit
I am new to redux, so I am trying to build a project using regular reducers and actions using typescript, but at the...
Read more >
Expected 0 arguments, but got 1 error in TypeScript | bobbyhadz
The error "Expected 0 arguments, but got 1" occurs when we pass an argument to a function that doesn't take any arguments. To...
Read more >
Usage With TypeScript - Redux Toolkit
Redux Toolkit is written in TypeScript, and its API is designed to enable great integration with TypeScript applications.
Read more >
How to Use Thunks with Redux Toolkit and TypeScript
Let's change our app a bit and, as an example, create a method to load todos from the server and show them. Refactoring#....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found