diff --git a/docs/react.html b/docs/react.html index a3725830..3e089aea 100644 --- a/docs/react.html +++ b/docs/react.html @@ -221,8 +221,10 @@ } const element = ( - <div>{addNumbers(2, 5)}</div> -) + <div> + {addNumbers(2, 5)} + </div> +);
import { useState } from 'react'
@@ -239,19 +241,6 @@
);
}
-import { Fragment } from 'react'
-import Avatar from './Avatar';
-import Profile from './Profile';
-
-const Student = () => (
- <Fragment>
- <Avatar src="./demo.jpg" />
- <Profile username="name" />
- </Fragment>
-)
-
-从 v16.2.0
开始 Fragment
可用于返回多个子节点,而无需向 DOM 添加额外的包装节点。或者使用 <></>
效果是一样的。
React 并没有创建一个新的 div
。它只是把子元素渲染到 domNode
中。domNode
是一个可以在任何位置的有效 DOM 节点。
render() {
@@ -262,6 +251,41 @@
}
提供了一种将子节点渲染到存在于父组件以外的 DOM 节点的优秀的方案
+import { Fragment } from 'react'
+import Avatar from './Avatar';
+import Profile from './Profile';
+
+const Student = () => (
+ <Fragment>
+ <Avatar src="./demo.jpg" />
+ <Profile username="name" />
+ </Fragment>
+);
+
+从 v16.2.0
开始 Fragment
可用于返回多个子节点,而无需向 DOM 添加额外的包装节点。或者使用 <></>
效果是一样的。
const Student = () => (
+ <>
+ <Avatar src="./demo.jpg" />
+ <Profile username="name" />
+ </>
+);
+
+
+render() {
+ return 'Look ma, no spans!';
+}
+
+您可以只返回一个字符串。查看: Fragments & strings
+const Student = () => [
+ <li key="A">First item</li>,
+ <li key="B">Second item</li>
+];
+
+不要忘记 key
!查看: Fragments & strings
const FancyButton = React.forwardRef(
(props, ref) => (
@@ -280,7 +304,7 @@
</FancyButton>;
import { Component,createRef } from 'react';
+import {Component,createRef} from 'react'
class MyComponent extends Component {
constructor(props) {
@@ -714,33 +738,6 @@
···
}
-
import React from 'react';
-import UserAvatar from "./UserAvatar";
-
-export default function UserProfile() {
- return (
- <div className="UserProfile">
- <UserAvatar />
- <UserAvatar />
- </div>
- );
-}
-
-注意:假设 UserAvatar
在 UserAvatar.js
中声明。
import React from 'react';
-import CompName from 'component-name';
-
-export default function UserProfile() {
- return (
- <div className="UserProfile">
- <CompName />
- </div>
- );
-}
-
-注意:外部组件在 npmjs.com 上找到,需要先安装导入。
import React, { Component } from 'react';
// 高阶组件 with
@@ -764,6 +761,79 @@
const MyComp = with('Hello')(LowComponent)
+function FancyBorder(props) {
+ return (
+ <div className={'Fancy'+props.color}>
+ {props.children}
+ </div>
+ );
+}
+
+组件可以通过 JSX 嵌套
+function WelcomeDialog() {
+ return (
+ <FancyBorder color="blue">
+ <h1 className="title">欢迎</h1>
+ <p className="message">
+ 感谢您访问我们的宇宙飞船
+ </p>
+ </FancyBorder>
+ );
+}
+
+function SplitPane(props) {
+ return (
+ <div className="SplitPane">
+ <div className="left">
+ {props.left}
+ </div>
+ <div className="right">
+ {props.right}
+ </div>
+ </div>
+ );
+}
+
+function App() {
+ return (
+ <SplitPane
+ left={<Contacts />}
+ right={<Chat />}
+ />
+ );
+}
+
+给组件 SplitPane
传递 left
和 right
两个组件参数
import React from 'react';
+import UserAvatar from "./UserAvatar";
+
+export default function UserProfile() {
+ return (
+ <div className="UserProfile">
+ <UserAvatar />
+ <UserAvatar />
+ </div>
+ );
+}
+
+注意:假设 UserAvatar
在 UserAvatar.js
中声明
import React from 'react';
+import {Button} from 'uiw';
+export default function UserProfile() {
+ return (
+ <div className="UserProfile">
+ <Button type="primary">
+ 主要按钮
+ </Button>
+ </div>
+ );
+}
+
+注意:外部组件在 npmjs.com 上找到,需要先安装导入
声明 message
为类的实例