import React from 'react'
import { useState } from 'react'
export default function About(props) {
const [theme,setTheme] = useState(null)
function toggle(option){
if(option==="light"){
setTheme({
color:"black",
backgroundColor:"white",
width:"90%",
marginInline:"auto"
})
console.log(theme,option==="light");
// return theme
}else if(option==="dark"){
setTheme({
color:"white",
backgroundColor:"black",
width:"90%",
marginInline:"auto"
})
console.log(theme,option==="light");
// return theme
}else{
setTheme({
color:"white",
backgroundColor:"#032f3c",
width:"90%",
marginInline:"auto"
})
console.log(theme,option==="light");
// return theme
}
}
return (
<div >
{toggle(props.theme)}
<div class="accordion" id="accordionExample" >
<div class="accordion-item" style={theme}>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample" >
<div class="accordion-body" >
/content/
</div>
</div>
</div>
我正试图根据(props.theme)的值来更改页面的主题
但当我调用函数toggle作为返回时,它会说render too times,但在不调用函数的情况下,该函数组件会在页面上显示bootstrap框架的默认值。