how to pass state data to other componentReactJS Two components communicatingPass props to parent component in React.jsCorrect modification of state arrays in ReactJSBest practice for ReactJS form componentsreact-router - pass props to handler componentWhat is the difference between state and props in React?React js onClick can't pass value to methodCan you force a React component to rerender without calling setState?How to conditionally add attributes to React components?How to pass props to this.props.children

Why Faces eat each other?

What can cause an unfrozen indoor copper drain pipe to crack?

Is it a Munchausen Number?

Why are thrust reversers not used to slow down to taxi speeds?

What is a good way to allow only one non null field in an object

How do I minimise waste on a flight?

How did Captain Marvel know where to find these characters?

Add Columns to .csv from Multiple Files

Is it possible to reduce the cost of brewing potions?

Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019

I might have messed up in the 'Future Work' section of my thesis

resoldering copper waste pipe

Which spells are in some way related to shadows or the Shadowfell?

What is the minimum required technology to reanimate someone who has been cryogenically frozen?

My perfect evil overlord plan... or is it?

Is it safe to keep the GPU on 100% utilization for a very long time?

Was Mohammed the most popular first name for boys born in Berlin in 2018?

Why did Missandei say this?

Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?

Are on’yomi words loanwords?

How is it possible for this circuit to continue functioning correctly?

Renting a house to a graduate student in my department

Bulk API Error: UNABLE_TO_LOCK_ROW:unable to obtain exclusive access to this record or 124 records

What Firewall Port is required for snap package management?



how to pass state data to other component


ReactJS Two components communicatingPass props to parent component in React.jsCorrect modification of state arrays in ReactJSBest practice for ReactJS form componentsreact-router - pass props to handler componentWhat is the difference between state and props in React?React js onClick can't pass value to methodCan you force a React component to rerender without calling setState?How to conditionally add attributes to React components?How to pass props to this.props.children






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am new to React. Here is the problem.
when I change the switch state I want to change the theme of whole app.



This is my switch component on the sidebar



constructor() 
super();
this.state = checked: false ;
this.handleChange = this.handleChange.bind(this);


handleChange(checked)
this.setState( checked );
console.log('ddd');

render()
return (
<Switch
checked=this.state.checked
onChange=this.handleChange
onColor='#86d3ff'
onHandleColor='#0061ac'
handleDiameter=20
uncheckedIcon=false
checkedIcon=false
boxShadow='0px 1px 5px rgba(0, 0, 0, 0.6)'
activeBoxShadow='0px 0px 1px 10px rgba(0, 0, 0, 0.2)'
height=10
width=30
className='react-switch'
id=this.props.id
/>
);



and this is route component that contained by ThemeProvider



<ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
...
</ThemeProvider>


I want to change the whole app theme when I click on the switch. (Sorry for bad English)










share|improve this question
























  • Use React Context API

    – Avinash Mahlawat
    Mar 23 at 8:28

















0















I am new to React. Here is the problem.
when I change the switch state I want to change the theme of whole app.



This is my switch component on the sidebar



constructor() 
super();
this.state = checked: false ;
this.handleChange = this.handleChange.bind(this);


handleChange(checked)
this.setState( checked );
console.log('ddd');

render()
return (
<Switch
checked=this.state.checked
onChange=this.handleChange
onColor='#86d3ff'
onHandleColor='#0061ac'
handleDiameter=20
uncheckedIcon=false
checkedIcon=false
boxShadow='0px 1px 5px rgba(0, 0, 0, 0.6)'
activeBoxShadow='0px 0px 1px 10px rgba(0, 0, 0, 0.2)'
height=10
width=30
className='react-switch'
id=this.props.id
/>
);



and this is route component that contained by ThemeProvider



<ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
...
</ThemeProvider>


I want to change the whole app theme when I click on the switch. (Sorry for bad English)










share|improve this question
























  • Use React Context API

    – Avinash Mahlawat
    Mar 23 at 8:28













0












0








0








I am new to React. Here is the problem.
when I change the switch state I want to change the theme of whole app.



This is my switch component on the sidebar



constructor() 
super();
this.state = checked: false ;
this.handleChange = this.handleChange.bind(this);


handleChange(checked)
this.setState( checked );
console.log('ddd');

render()
return (
<Switch
checked=this.state.checked
onChange=this.handleChange
onColor='#86d3ff'
onHandleColor='#0061ac'
handleDiameter=20
uncheckedIcon=false
checkedIcon=false
boxShadow='0px 1px 5px rgba(0, 0, 0, 0.6)'
activeBoxShadow='0px 0px 1px 10px rgba(0, 0, 0, 0.2)'
height=10
width=30
className='react-switch'
id=this.props.id
/>
);



and this is route component that contained by ThemeProvider



<ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
...
</ThemeProvider>


I want to change the whole app theme when I click on the switch. (Sorry for bad English)










share|improve this question
















I am new to React. Here is the problem.
when I change the switch state I want to change the theme of whole app.



This is my switch component on the sidebar



constructor() 
super();
this.state = checked: false ;
this.handleChange = this.handleChange.bind(this);


handleChange(checked)
this.setState( checked );
console.log('ddd');

render()
return (
<Switch
checked=this.state.checked
onChange=this.handleChange
onColor='#86d3ff'
onHandleColor='#0061ac'
handleDiameter=20
uncheckedIcon=false
checkedIcon=false
boxShadow='0px 1px 5px rgba(0, 0, 0, 0.6)'
activeBoxShadow='0px 0px 1px 10px rgba(0, 0, 0, 0.2)'
height=10
width=30
className='react-switch'
id=this.props.id
/>
);



and this is route component that contained by ThemeProvider



<ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
...
</ThemeProvider>


I want to change the whole app theme when I click on the switch. (Sorry for bad English)







reactjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 9:01









Leslie Alldridge

607




607










asked Mar 23 at 7:53









uugan bayaruugan bayar

11




11












  • Use React Context API

    – Avinash Mahlawat
    Mar 23 at 8:28

















  • Use React Context API

    – Avinash Mahlawat
    Mar 23 at 8:28
















Use React Context API

– Avinash Mahlawat
Mar 23 at 8:28





Use React Context API

– Avinash Mahlawat
Mar 23 at 8:28












2 Answers
2






active

oldest

votes


















0














Can you please try



 handleChange(checked) 
this.setState( checked: true );
console.log('ddd');



As the code here runs on this.state.checked being true or false. Your current code will set the state to be checked:checked instead of checked:true.



If this doesn't help, use React dev tools in your web browser to see what state is doing.



<ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
...
</ThemeProvider>





share|improve this answer






























    0














    You can put your component state value to the redux store (or use mobx or react Context) which it can be used by other components.



    // switch component
    handleChange(checked)
    this.props.appActions.setAppTheme( checked ); // this action will set the value to redux store, you should implement the action and reducer method by yourself


    // other component
    <ThemeProvider theme= mode: this.props.appState.checked ? 'dark' : 'light' >
    // other component connect to the redux store so it can get the state value
    </ThemeProvider>





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311767%2fhow-to-pass-state-data-to-other-component%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Can you please try



       handleChange(checked) 
      this.setState( checked: true );
      console.log('ddd');



      As the code here runs on this.state.checked being true or false. Your current code will set the state to be checked:checked instead of checked:true.



      If this doesn't help, use React dev tools in your web browser to see what state is doing.



      <ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
      ...
      </ThemeProvider>





      share|improve this answer



























        0














        Can you please try



         handleChange(checked) 
        this.setState( checked: true );
        console.log('ddd');



        As the code here runs on this.state.checked being true or false. Your current code will set the state to be checked:checked instead of checked:true.



        If this doesn't help, use React dev tools in your web browser to see what state is doing.



        <ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
        ...
        </ThemeProvider>





        share|improve this answer

























          0












          0








          0







          Can you please try



           handleChange(checked) 
          this.setState( checked: true );
          console.log('ddd');



          As the code here runs on this.state.checked being true or false. Your current code will set the state to be checked:checked instead of checked:true.



          If this doesn't help, use React dev tools in your web browser to see what state is doing.



          <ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
          ...
          </ThemeProvider>





          share|improve this answer













          Can you please try



           handleChange(checked) 
          this.setState( checked: true );
          console.log('ddd');



          As the code here runs on this.state.checked being true or false. Your current code will set the state to be checked:checked instead of checked:true.



          If this doesn't help, use React dev tools in your web browser to see what state is doing.



          <ThemeProvider theme= mode: this.state.checked ? 'dark' : 'light' >
          ...
          </ThemeProvider>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 8:18









          Leslie AlldridgeLeslie Alldridge

          607




          607























              0














              You can put your component state value to the redux store (or use mobx or react Context) which it can be used by other components.



              // switch component
              handleChange(checked)
              this.props.appActions.setAppTheme( checked ); // this action will set the value to redux store, you should implement the action and reducer method by yourself


              // other component
              <ThemeProvider theme= mode: this.props.appState.checked ? 'dark' : 'light' >
              // other component connect to the redux store so it can get the state value
              </ThemeProvider>





              share|improve this answer



























                0














                You can put your component state value to the redux store (or use mobx or react Context) which it can be used by other components.



                // switch component
                handleChange(checked)
                this.props.appActions.setAppTheme( checked ); // this action will set the value to redux store, you should implement the action and reducer method by yourself


                // other component
                <ThemeProvider theme= mode: this.props.appState.checked ? 'dark' : 'light' >
                // other component connect to the redux store so it can get the state value
                </ThemeProvider>





                share|improve this answer

























                  0












                  0








                  0







                  You can put your component state value to the redux store (or use mobx or react Context) which it can be used by other components.



                  // switch component
                  handleChange(checked)
                  this.props.appActions.setAppTheme( checked ); // this action will set the value to redux store, you should implement the action and reducer method by yourself


                  // other component
                  <ThemeProvider theme= mode: this.props.appState.checked ? 'dark' : 'light' >
                  // other component connect to the redux store so it can get the state value
                  </ThemeProvider>





                  share|improve this answer













                  You can put your component state value to the redux store (or use mobx or react Context) which it can be used by other components.



                  // switch component
                  handleChange(checked)
                  this.props.appActions.setAppTheme( checked ); // this action will set the value to redux store, you should implement the action and reducer method by yourself


                  // other component
                  <ThemeProvider theme= mode: this.props.appState.checked ? 'dark' : 'light' >
                  // other component connect to the redux store so it can get the state value
                  </ThemeProvider>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 23 at 8:23









                  zhaozhimingzhaozhiming

                  401314




                  401314



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311767%2fhow-to-pass-state-data-to-other-component%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해