微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

所有面板都处于非活动状态

如何解决所有面板都处于非活动状态

当我更改“activeKey”时,所有面板都处于非活动状态。为什么?

import React,{useEffect,useState} from "react";
import { Collapse } from 'antd';

const { Panel } = Collapse;

const text = `
  A dog is a type of domesticated animal.
  KNown for its loyalty and faithfulness,it can be found as a welcome guest in many households across the world.
`;

export default function Abc() {

    setTimeout(() => {
        setopenKey(["2"])
    },3000)

    const [openKey,setopenKey] = useState(["1"])

    return (
        <div>
            <Collapse accordion activeKey={openKey} >
                <Panel header="This is panel header 1" key="1">
                    <p>{text}</p>
                </Panel>
                <Panel header="This is panel header 2" key="2">
                    <p>{text}</p>
                </Panel>
                <Panel header="This is panel header 3" key="3">
                    <p>{text}</p>
                </Panel>
            </Collapse>
        </div>
    )
}

我的目标是在打开或关闭面板时通过“useState”钩子。

解决方法

当您使用 #include "LCD.h" #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define Trigger_pin PA0 /* sensor 1 trig pin*/ int TimerOverflow = 0; long TimerOverflow1 = 0; long pulse = 0; static volatile int i = 0; void US1(); void US2(); ISR(TIMER1_OVF_vect) { TimerOverflow++; /* Increment Timer Overflow count */ } ISR(INT0_vect) { if (i==1) { TCCR0=0; pulse=TCNT0; TCNT0=0; i=0; } if (i==0) { TCCR0|=(1<<CS00); TCNT0=0; i=1; } } int main(void) { DIO_init(); LCD_init(); DDRC=0xff; DDRA |= (1<<PINA0); PORTC=0x00; DDRD = 0b10111011; PORTD=0xff; sei(); /* Enable global interrupt */ TIMSK |= (1 << TOIE1); /* Enable Timer1 overflow interrupts */ TCCR1A = 0; TCCR0 = 0; GICR|=(1<<INT0); MCUCR|=(1<<ISC00); LCD_StringPos(2,10,"A5"); while (1) { US1(); US2(); } } void US1() { long count; int distance; char st_lcd[10]; /* Give 10us trigger pulse on trig. pin to HC-SR04 */ PORTA |= (1 << Trigger_pin); _delay_us(15); PORTA &= (~(1 << Trigger_pin)); _delay_us(15); TCNT1 = 0; /* Clear Timer counter */ TCCR1B = 0x41; /* Capture on rising edge,No prescaler*/ TIFR = 1<<ICF1; /* Clear ICP flag (Input Capture flag) */ TIFR = 1<<TOV1; /* Clear Timer Overflow flag */ /*Calculate width of Echo by Input Capture (ICP) */ while ((TIFR & (1 << ICF1)) == 0);/* Wait for rising edge */ TCNT1 = 0; /* Clear Timer counter */ TCCR1B = 0x01; /* Capture on falling edge,No prescaler */ TIFR = 1<<ICF1; /* Clear ICP flag (Input Capture flag) */ TIFR = 1<<TOV1; /* Clear Timer Overflow flag */ TimerOverflow = 0;/* Clear Timer overflow count */ while ((TIFR & (1 << ICF1)) == 0);/* Wait for falling edge */ count = ICR1 + (65535 * TimerOverflow); /* Take count */ //freq=count/F_CPU; //freq = /* 8MHz Timer freq,sound speed =343 m/s */ distance=count/933; itoa(distance,st_lcd,10); LCD_StringPos(2,5,st_lcd); _delay_ms(1000); } void US2() { long count=0; int dist=0; PORTD|=(1<<PIND0); _delay_us(15); PORTD &=~(1<<PIND0); char st_lcd2[10]; count=pulse; dist=count/933; itoa(dist,st_lcd2,10); LCD_StringPos(1,st_lcd2); _delay_ms(900); } 时,表示该组件是受控组件。您应该在 activeKey 处理程序中更改 activeKey 以激活其他面板。

你可以这样做

onChange

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。