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.

Provide a `useStyles` method for using with React Hooks API

See original GitHub issue

I imagine the API should not be too different from the HOC. The README example would look like this:

import React from "react";
import { css, useStyles } from "./useStyles";

function MyComponent() {
  const styles = useStyles(({ color }) => ({
    firstLink: {
      color: color.primary
    },

    secondLink: {
      color: color.secondary
    }
  }));

  return (
    <div>
      <a href="/somewhere" {...css(styles.firstLink)}>
        A link to somewhere
      </a>{" "}
      and{" "}
      <a href="/somewhere-else" {...css(styles.secondLink)}>
        a link to somewhere else
      </a>
    </div>
  );
}

export default MyComponent;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
mohsen1commented, Feb 27, 2019

Closing based on feedback. Styles are not a stateful part of the component so it doesn’t make sense to use Hooks API for them.

2reactions
mohsen1commented, Sep 11, 2019

For anyone landing here good news is that there is a useStyles hook available. //cc @noratarano

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks API Reference - React
This page describes the APIs for the built-in Hooks in React. ... Unlike the setState method found in class components, useState does not...
Read more >
How to style components using makeStyles and still have ...
What we ended up doing is stopped using the class components and created Functional Components, using useEffect() from the Hooks API for lifecycle...
Read more >
Material-UI makeStyles, useStyles, createStyles, and ...
Material-UI withStyles was the primary method for wrapping a component ... Preferably, you are using React hooks and the MUI makeStyles hook ...
Read more >
Styling in React - React Hooks Handbook - Design+Code
How to style your React components using inline styling, separate stylesheets or styled-components.
Read more >
Styles API - MUI System
Link a style sheet with a function component using the hook pattern. ... as React from 'react'; import { makeStyles } from '@mui/styles';...
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