codemotionapps/react-native-dark-mode

Invariant Violation: invalid hook call Error

Closed this issue · 2 comments

Hello,

i'm getting this error when I try to call any methods
IMG_6059BB7D8C6F-1

My package.json:

"react": "16.10.1",
"react-native": "0.61.2",
"react-native-dark-mode": "^0.1.0",

iOS: 13.1.1
Xcode: 11.0

Can you please help me to fix?

Thanks!

Seems like you're trying to use this package in a class component. Please check out the docs to learn how to use hooks: https://reactjs.org/docs/hooks-intro.html
This library is not made to be used with class components.

Not a perfect fix, and it's a shame this library is so biased against class components, but since all I needed was the initial dark mode state of my device, the following did the trick:

import { initialMode } from 'react-native-dark-mode'

static isDarkModeEnabled = () => {
    return initialMode === 'dark'
}