如何使用基于支持的动态密钥初始化状态?道具是从外部源(异步)获取的数据。因此,当数据被成功下载时,道具将发生变化。考虑一下像这样的组件。
编辑:我想使状态动态,因为我想要生成一个对话框(弹出)的基础上,被点击的项目。DialogContainer基本上是这样的。visible螺旋桨将使该对话框可见,而onHide支柱将隐藏该对话框。我用。
class SomeComponent extends React.Component {
constructor() {
super();
this.state = {};
// the key and value will b
我正在开发一个简单的网站使用React + nextJS。
为了保持简单,假设我有两次跌落。
Dropdown A (country)
- Dropdown B (run time options based on the country selection)
下拉列表A在主页上。下拉列表B是一个独立的组件,我设计了我的组件,如下所示。
class MySubComponent extents Component{
state = {
options: []
}
static async getDerivedStateFromPro
考虑到下面的组件结构,我不想更新我的父级状态,然后应该更新我的GrandChild。我知道我可以使它工作,使儿童无国籍或只更新国家在儿童,但在我们的应用程序,这是目前的结构。有什么好办法来做这件事吗?还是我们应该重新设计?我们在父级中保持状态,因为我们不想向应用程序中的许多http请求发出状态。在父类中,我们获取所需的数据并进行初始修改。然后将这些数据发送到其他组件,而这些组件又具有子组件,因此出现了示例结构。
在本例中打印的内容:Test: 1235
import * as React from 'react';
import * as ReactDOM from '
我在redux中尝试通过函数操作发送数据时遇到问题,我的代码如下 import React from 'react'
import {connect} from 'react-redux'
import {RetrieveCompany} from '../../folder/action/my.actions'
interface Icampaing{
campaing: my_data
}
// campaing IS WORKING WELL, GET ME ALL MY DATA
const Personal: React.F
我在按钮上设置了一个简单的属性,并试图在DOM中显示它.我不明白我做错了什么。我看到了Click Me! Current numer is,但没有看到Click Me! Current numer is 1。我一定是漏掉了什么?没有错误。
class TestElement extends Component {
render(){
return (
<div>
<Header />
<div>
<bu
所以我有两个组件,一个是MainComponent,另一个是用ReactJS编写的MenuComponent。
将MenuComponent导入到MainComponent
MainComponent如下所示:
import React, { Component } from 'react';
import { Navbar, NavbarBrand } from 'reactstrap';
import Menu from './MenuComponent';
import DishDetail from './DishdetailCo