What causes the JSS error "<Hook />'s styles function doesn't rely on the "theme" argument"?

Viewed 208

Unfortunately there are no helpful details when it comes to this error when I run my Jest tests:

Warning: [JSS] <Hook />'s styles function doesn't rely on the "theme" argument. We recommend declaring styles as an object instead.

Does anyone know how to locate the problem and how to fix it?

1 Answers

For anyone encountering the same problem I found a helpful plugin for eslint that prints out the exact location of the error: https://www.npmjs.com/package/eslint-plugin-react-jss

The error itself is caused by defining a function inside the createUseStyles function instead of simply using an object if only static information is needed.

Erroneous:

createUseStyles((...) => ({
    Foo: {
        color: 'red',
        ...
    },
}));

Working:

createUseStyles({
    Foo: {
        color: 'red',
        ...
    },
});
Related