首页 > 解决方案 > 模态不打开反应js

问题描述

我有一个打开我的模式的功能,该功能基于我传递给我的 Body 组件的道具功能激活,该功能改变了我的主类 App 中的状态,当我单击我放置在切换菜单中的锚点时,它会打开模式但是我正在尝试制作一个自动运行代码的演示。演示功能在我的 Body 组件中 当我运行演示功能时,它会打开菜单但不会打开我的笔记模式。

该函数在从演示运行时也会输出正确的值,只是不会弹出模态框。

//I have the following state:

this.state={
  showNotes: false

//this function changes the state
openNotes = () =>{
      console.log("opening notes")
      this.setState({showNotes:!this.state.showNotes})
  }

//I pass this function as a prop to my body component
  <Route path="/app" render ={props=><Body {...props} openNotes={this.openNotes} />}/>


//inside body I use this function to create a demo of everything in the app. 


rundemo=()=>{
  console.log("run the demo")
  let counter=0
    console.log("begin the wait")
  while (counter < 10000){
    counter+=1
    console.log(counter)
  }

  counter=0
  this.props.setHighlightMode()
  while (counter < 10000){
    counter+=1
  }

  var docvalue= document.getElementById('regex-example').value
  var selection = this.range(0,20,docvalue)//get selected chars in element

  console.log("document value",docvalue)
  console.log("selection in range",selection)
  var selectedText = selection.toString(); //sends the elements to a string
  console.log("selection text to update",selectedText)
  {this.props.updateHighlight(selectedText)} //send highlight to main to send to notes


  while (counter < 10000){
    counter+=1
  }
  this.props.setHighlightMode()
  counter=0
  while (counter < 10000){
    counter+=1
  }
    this.props.toggleMenu()
    while (counter < 10000){
      counter+=1
    }

this.props.openNotes()
  counter=0
  while (counter < 10000){
    counter+=1
  }

  counter=0
  while (counter < 10000){
    counter+=1
  }
  this.props.close()
  counter=0
  this.props.setScholarMode()
  this.props.DemosynonymsFunction(selectedText.toString())
  console.log("next return a synonym")
}      

标签: javascriptreactjs

解决方案


推荐阅读