0

It seems if I create a function to return a dom element with a className associated, the local style does not get applied e.g;

export default function thing(){
    const elem = function(){
        return (<div className="myCss">Hello</div>)
    }
    
    return(
        <>
            { elem() }
            <style jsx>{` .myCss{ color:#f00 } `}</style>
        </>

    )    
}

My expectation is that elem() would return an element that would inherit the style associated to the .myCss class. But it doesn't :/

1

1 Answer 1

1

By default styled-jsx transpiles the stylenames, so your example generates dynamic styles e.g: .mycss-123 - If you want .myCss to be intact, add global - Additionally, your template string contains spaces.

This works.

<style jsx global>{`.myCss{ color:red }`}</style>
Sign up to request clarification or add additional context in comments.

1 Comment

This is the correct answer, I've discovered. Unfortunately, hot reloading works weird with this tag :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.