'Cannot assign theme in React
I need to compile a UniswapV2 fork, but it doesn't want to compile. The error is below.
TypeScript error in /src/components/AccountDetails/index.tsx(230,28): Argument of type 'import("/node_modules/@types/react-redux/node_modules/@types/react/index").Context<import("/node_modules/@types/styled-components/index").DefaultTheme>' is not assignable to parameter of type 'React.Context<import("/node_modules/@types/styled-components/index").DefaultTheme>'. TS2345
228 | }: AccountDetailsProps) {
229 | const { chainId, account, connector } = useActiveWeb3React()
> 230 | const theme = useContext(ThemeContext)
| ^
231 | const dispatch = useDispatch<AppDispatch>()
232 |
233 | function formatConnectorName() {
Theme context is defined like this:
export const ThemeContext: React.Context<AnyIfEmpty<DefaultTheme>>;
Solution 1:[1]
You are using a single iterator both in a loop and using next
. That can get confusing. Think about it:
- at iteration
i
,line
is linek
andnext_line
is linek+1
. - at iteration
i+1
,line
is now linek+2
.
You need to pass/save one line between iterations. Using a sample file of consecutive numbers in each line:
1
2
3
...
Using the code:
with open("text.txt") as file:
line = next(file)
for next_line in file:
print(line.strip())
print(next_line.strip())
print("---")
line = next_line
Will give:
1
2
---
2
3
---
3
4
---
...
Solution 2:[2]
You could simply track the previous line, separately, at update at the end of each iteration:
prev_line = None
with open("THUMlog.txt", "r") as file:
for line in file:
if line == "#DATE TIME TEMPERATURE UNIT HUMIDITY%\n":
continue
stripped_line = line.rstrip().split()
if prev_line:
print(f"Stripped: {prev_line}")
print(f"Next: {line}")
prev_line = line
Solution 3:[3]
You can do this by rewinding the position within the current file.
with open(...) as fh:
pos = fh.tell() # This is where we want to go back to
# Do what ever you want such as read lines.
if INEEDTOGOBACK:
fh.seek(pos)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tomerikoo |
Solution 2 | Jedi |
Solution 3 | MYousefi |