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.

Changing theme programmatically

See original GitHub issue

As stated above is it possible to change the dark / light theme on function call or similiar. Looking to implement new prefers-color-scheme media query.

react-google-recaptcha version: 2.0.0-rc.1

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dozoischcommented, Aug 26, 2019

In this case you could simply do this:


import React, { Component } from 'react';
import ReCAPTCHA from 'react-google-recaptcha';

export default class Captcha extends Component {
  constructor(props) {
    super(props);
    this.state = {
      theme: null,
    };
  }

  componentDidMount() {
    const darkmode = document.querySelector('html').classList.contains('dark');
    if (darkmode) {
      this.setState({ theme: 'dark' });
    } else {
      this.setState({ theme: 'light' });
    }
  }

  render() {
    if (!this.state.theme) { return null; }
    return <ReCAPTCHA theme={this.state.theme} />;
  }
}
0reactions
b-botcommented, Sep 9, 2019

Awesome thanks for the help man, went with a different solution as that still had a delayed rendering. Ended up rendering both and hiding / displaying depending on body class. The swop-out is instant now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Activity's theme programmatically - android
This is the code i used when changing theme using preferences.. SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(this); String ...
Read more >
Change Android Theme Programmatically | by Ahmad Arif Faizin
Change Android Theme Programmatically ; override fun getTheme(): Resources.Theme { ; val theme = ; super.getTheme() ; when (intent.getStringExtra( ...
Read more >
How to Modify Themes Programmatically - Documentation
The theme can be either modified in Visual Style Builder or programatically. This article shows a sample approach how to customize the theme...
Read more >
Android Set Theme Dynamically - Java Articles
In this article Android Set Theme Dynamically "android change theme programmatically" we will see how to change the theme dynamically.
Read more >
Change the app theme - Android Developers
The full Material system includes design guidelines on visual, motion, and interaction design for your app, but this codelab will focus on ...
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