3.精通React-如何使用ReactHooks重构类组件?-《前端知识进阶》

admin 2025-11-01 15:29:27 编程 来源:ZONE.CI 全球网 0 阅读模式
  • 1. 管理和更新组件状态
  • 2. 状态更新后的操作
  • 3. 获取数据
  • 4. 卸载组件时清理副作用
  • 5. 防止组件重新渲染
  • 6. Context API
  • 7. 跨重新渲染保留值
  • 8. 如何向父组件传递状态和方法?
  • 9. 小结

    最初,在React中可以使用 createClass 来创建组件,后来被类组件所取代。在 React 16.8版本中,新增的 Hooks 功能彻底改变了我们编写React程序的方式,因为使用 hooks 可以编写更简洁、更清晰的代码,并为创建可重用的有状态逻辑提供了更好的模式。

    许多公司和开发人员都放弃了类组件转而使用 Hooks。而许多旧的的React 项目仍然在使用类组件。更重要的是,在类组件中有 Error Boundaries,而函数组件中是无法使用 Error Boundaries 的。

    本文就来通过一些常见示例看看如何使用 React Hooks 来重构类组件。

    1. 管理和更新组件状态

    状态管理是几乎所有 React 应用中最重要的部分,React 基于 state 和 props 渲染组件。每当它们发生变化时,组件就会重新渲染,并且 DOM 也会相应地更新。下面来看一个计数器的例子,它包含一个计数状态以及两个更新它的地方:

    1. import { Component } from "react";
    2. class ManagingStateClass extends Component {
    3. state = {
    4. counter: 0,
    5. };
    6. increment = () => {
    7. this.setState(prevState => {
    8. return {
    9. counter: prevState.counter + 1,
    10. };
    11. });
    12. };
    13. decrement = () => {
    14. this.setState(prevState => {
    15. return {
    16. counter: prevState.counter - 1,
    17. };
    18. });
    19. };
    20. render() {
    21. return (
    22. <div>
    23. <div>Count: {this.state.counter}</div>
    24. <div>
    25. <button onClick={this.increment}>Increment</button>
    26. <button onClick={this.decrement}>Decrement</button>
    27. </div>
    28. </div>
    29. );
    30. }
    31. }
    32. export default ManagingStateClass;

    下面来使用 Hooks 实现这个计数器组件:

    1. import { useState } from "react";
    2. const ManagingStateHooks = () => {
    3. const [counter, setCounter] = useState(0);
    4. const increment = () => setCounter(counter => counter + 1);
    5. const decrement = () => setCounter(counter => counter - 1);
    6. return (
    7. <div>
    8. <div>Count: {counter}</div>
    9. <div>
    10. <button onClick={increment}>Increment</button>
    11. <button onClick={decrement}>Decrement</button>
    12. </div>
    13. </div>
    14. );
    15. };
    16. export default ManagingStateHooks;

    该组件是一个返回 JSX 的函数,使用 useState hook来管理计算器的状态。它返回一个包含两个值的数组:第一个值为状态,第二个值为更新函数。并且使用 setCounter 来更新程序的incrementdecrement函数。

    2. 状态更新后的操作

    在某些情况下,我们可能需要在状态更新时执行某些操作。在类组件中,我们通常会在componentDidUpdate 生命周期中实现该操作。

    1. import { Component } from "react";
    2. class StateChangesClass extends Component {
    3. state = {
    4. counter: 0,
    5. };
    6. componentDidUpdate(prevProps, prevState) {
    7. localStorage.setItem("counter", this.state.counter);
    8. }
    9. increment = () => {
    10. this.setState(prevState => {
    11. return {
    12. counter: prevState.counter + 1,
    13. };
    14. });
    15. };
    16. decrement = () => {
    17. this.setState(prevState => {
    18. return {
    19. counter: prevState.counter - 1,
    20. };
    21. });
    22. };
    23. render() {
    24. return (
    25. <div>
    26. <div>Count: {this.state.counter}</div>
    27. <div>
    28. <button onClick={this.increment}>Increment</button>
    29. <button onClick={this.decrement}>Decrement</button>
    30. </div>
    31. </div>
    32. );
    33. }
    34. }
    35. export default StateChangesClass;

    当状态发生变化时,我们将新的计数器值保存在 localStorage 中。在函数组件中,我们可以通过使用 useEffect hook 来实现相同的功能。

    1. import { useState, useEffect } from "react";
    2. const StateChangesHooks = () => {
    3. const [counter, setCounter] = useState(0);
    4. const increment = () => setCounter(counter => counter + 1);
    5. const decrement = () => setCounter(counter => counter - 1);
    6. useEffect(() => {
    7. localStorage.setItem("counter", counter);
    8. }, [counter]);
    9. return (
    10. <div>
    11. <div>Count: {counter}</div>
    12. <div>
    13. <button onClick={increment}>Increment</button>
    14. <button onClick={decrement}>Decrement</button>
    15. </div>
    16. </div>
    17. );
    18. };
    19. export default StateChangesHooks;

    这个 useEffect hook 有两个参数,第一个参数是回调函数,第二个参数是依赖数组。在组件挂载时,这个 hook 至少会执行一次。然后,仅在依赖数组内的任何值发生变化时都会触发第一个参数传入的回调函数。如果依赖数组为空,则回调函数只会执行一次。在上面的例子中,每当 counter 发生变化时,都会触发将 counter 保存在 localStorage 中的回调函数。

    3. 获取数据

    在类组件中,通过会在componentDidMount生命周期中初始化一个 API 请求来获取数据。下面来看一个获取并显示帖子列表的组件:

    1. import { Component } from "react";
    2. class FetchingDataClass extends Component {
    3. state = {
    4. posts: [],
    5. };
    6. componentDidMount() {
    7. this.fetchPosts();
    8. }
    9. fetchPosts = async () => {
    10. const response = await fetch("https://jsonplaceholder.typicode.com/posts");
    11. const data = await response.json();
    12. this.setState({
    13. posts: data.slice(0, 10),
    14. });
    15. };
    16. render() {
    17. return (
    18. <div>
    19. {this.state.posts.map(post => {
    20. return <div key={post.id}>{post.title}</div>;
    21. })}
    22. </div>
    23. );
    24. }
    25. }
    26. export default FetchingDataClass

    有了 hooks,就可以使用useEffect来实现上述功能。它会在第一次挂载之后执行一次,然后在任何依赖发生变化时再次触发。useEffect 允许我们传入一个空依赖数组作为第二个参数来确保只执行一次effect的回调函数。

    1. import { useState, useEffect } from "react";
    2. const FetchingDataHooks = () => {
    3. const [posts, setPosts] = useState([]);
    4. const fetchPosts = async () => {
    5. const response = await fetch("https://jsonplaceholder.typicode.com/posts");
    6. const data = await response.json();
    7. setPosts(data.slice(0, 10));
    8. };
    9. useEffect(() => {
    10. fetchPosts();
    11. }, []);
    12. return (
    13. <div>
    14. {posts.map(post => {
    15. return <div key={post.id}>{post.title}</div>;
    16. })}
    17. </div>
    18. );
    19. };
    20. export default FetchingDataHooks;

    4. 卸载组件时清理副作用

    在卸载组件时清理副作用是非常重要的,否则可能会导致内存泄露。例如,在一个组件中,我们想要监听一个事件,比如resize或者scroll,并根据窗口大小或滚动的位置来做一些事情。下面来看一个类组件的例子,它会监听 resize 事件,然后更新浏览器窗口的宽度和高度的状态。事件监听器在 componentWillUnmount 生命周期中被移除。

    1. import { Component } from "react";
    2. class CleanupClass extends Component {
    3. state = {
    4. width: window.innerWidth,
    5. height: window.innerHeight,
    6. };
    7. componentDidMount() {
    8. window.addEventListener("resize", this.updateWindowSize, {
    9. passive: true,
    10. });
    11. }
    12. componentWillUnmount() {
    13. window.removeEventListener("resize", this.updateWindowSize, {
    14. passive: true,
    15. });
    16. }
    17. updateWindowSize = () => {
    18. this.setState({
    19. width: window.innerWidth,
    20. height: window.innerHeight,
    21. });
    22. };
    23. render() {
    24. return (
    25. <div>
    26. Window: {this.state.width} x {this.state.height}
    27. </div>
    28. );
    29. }
    30. }
    31. export default CleanupClass;

    useEffect 中,我们可以在回调函数中返回一个函数来执行清理操作,卸载组件时会调用此函数。下面,首先来定义一个 updateWindowSize 函数,然后在 useEffect 中添加 resize 事件监听器。 接下来返回一个匿名箭头函数,它将用来移除监听器。

    1. import { useState, useEffect } from "react";
    2. const CleanupHooks = () => {
    3. const [width, setWidth] = useState(window.innerWidth);
    4. const [height, setHeight] = useState(window.innerHeight);
    5. useEffect(() => {
    6. const updateWindowSize = () => {
    7. setWidth(window.innerWidth);
    8. setHeight(window.innerHeight);
    9. };
    10. window.addEventListener("resize", updateWindowSize, {
    11. passive: true,
    12. });
    13. return () => {
    14. window.removeEventListener("resize", this.updateWindowSize, {
    15. passive: true,
    16. });
    17. };
    18. }, []);
    19. return (
    20. <div>
    21. Window: {this.state.width} x {this.state.height}
    22. </div>
    23. );
    24. };
    25. export default CleanupHooks;

    5. 防止组件重新渲染

    React 非常快,通常我们不必担心过早的优化。但是,在某些情况下,优化组件并确保它们不会过于频繁地重新渲染是很有必要的。

    例如,减少类组件重新渲染的常用方法是使用 PureComponent 或者 shouldComponentUpdate 生命周期。下面例子中有两个类组件(父组件和子组件),父组件有两个状态值:counterfruit。子组件只在父组件的 fruit 发生变化时重新渲染。所以,使用 shouldComponentUpdate 生命周期来检查 fruit 属性是否改变。 如果相同,则子组件不会重新渲染。

    父组件:

    1. import { Component } from "react";
    2. import PreventRerenderClass from "./PreventRerenderClass.jsx";
    3. function randomInteger(min, max) {
    4. return Math.floor(Math.random() * (max - min + 1)) + min;
    5. }
    6. const fruits = ["banana", "orange", "apple", "kiwi", "mango"];
    7. class PreventRerenderExample extends Component {
    8. state = {
    9. fruit: null,
    10. counter: 0,
    11. };
    12. pickFruit = () => {
    13. const fruitIdx = randomInteger(0, fruits.length - 1);
    14. const nextFruit = fruits[fruitIdx];
    15. this.setState({
    16. fruit: nextFruit,
    17. });
    18. };
    19. componentDidMount() {
    20. this.pickFruit();
    21. }
    22. render() {
    23. return (
    24. <div>
    25. <h3>
    26. Current fruit: {this.state.fruit} | counter: {this.state.counter}
    27. </h3>
    28. <button onClick={this.pickFruit}>挑一个水果</button>
    29. <button
    30. onClick={() =>
    31. this.setState(({ counter }) => ({
    32. counter: counter + 1,
    33. }))
    34. }
    35. >
    36. Increment
    37. </button>
    38. <button
    39. onClick={() =>
    40. this.setState(({ counter }) => ({ counter: counter - 1 }))
    41. }
    42. >
    43. Decrement
    44. </button>
    45. <div className="section">
    46. <PreventRerenderClass fruit={this.state.fruit} />
    47. </div>
    48. </div>
    49. );
    50. }
    51. }
    52. export default PreventRerenderExample;

    子组件:

    1. import { Component } from "react";
    2. class PreventRerenderClass extends Component {
    3. shouldComponentUpdate(nextProps, nextState) {
    4. return this.props.fruit !== nextProps.fruit;
    5. }
    6. render() {
    7. return (
    8. <div>
    9. <p>Fruit: {this.props.fruit}</p>
    10. </div>
    11. );
    12. }
    13. }
    14. export default PreventRerenderClass;

    随着 hooks 的引入,我们得到了一个新的高阶组件,称为 memo。它可用于优化性能并防止函数组件重新渲染。下面来看看它是怎么用的。

    父组件:

    1. import { useState, useEffect } from "react";
    2. import PreventRerenderHooks from "./PreventRerenderHooks.jsx";
    3. function randomInteger(min, max) {
    4. return Math.floor(Math.random() * (max - min + 1)) + min;
    5. }
    6. const fruits = ["banana", "orange", "apple", "kiwi", "mango"];
    7. const PreventRerenderExample = () => {
    8. const [fruit, setFruit] = useState(null);
    9. const [counter, setCounter] = useState(0);
    10. const pickFruit = () => {
    11. const fruitIdx = randomInteger(0, fruits.length - 1);
    12. const nextFruit = fruits[fruitIdx];
    13. setFruit(nextFruit);
    14. };
    15. useEffect(() => {
    16. pickFruit();
    17. }, []);
    18. return (
    19. <div>
    20. <h3>
    21. Current fruit: {fruit} | counter: {counter}
    22. </h3>
    23. <button onClick={pickFruit}>挑一个水果</button>
    24. <button onClick={() => setCounter(counter => counter + 1)}>
    25. Increment
    26. </button>
    27. <button onClick={() => setCounter(counter => counter - 1)}>
    28. Decrement
    29. </button>
    30. <div className="section">
    31. <PreventRerenderHooks fruit={fruit} />
    32. </div>
    33. </div>
    34. );
    35. };
    36. export default PreventRerenderExample;

    子组件:

    1. import { memo } from "react";
    2. const PreventRerenderHooks = props => {
    3. return (
    4. <div>
    5. <p>Fruit: {props.fruit}</p>
    6. </div>
    7. );
    8. };
    9. export default memo(PreventRerenderHooks);

    PreventRerenderHooks 组件使用 memo 组件包装,并且仅在 props 中的 fruit 发生变化时发挥重新渲染。需要注意,memo组件执行的是浅比较,因此如果需要更好地控制memo组件何时重新渲染,可以提供自己的函数来执行 props 比较。

    1. import { memo } from "react";
    2. const PreventRerenderHooks = props => {
    3. return (
    4. <div>
    5. <p>Fruit: {props.fruit}</p>
    6. </div>
    7. );
    8. };
    9. export default memo(PreventRerenderHooks, (prevProps, nextProps) => {
    10. return prevProps.fruit !== nextProps.fruit
    11. });

    6. Context API

    Context API 是一个很好用的工具,可以为组件层次结构中不同级别的组件提供值。 可以使用 React 提供的 createContext 方法创建新的上下文。先来看一个在类组件中使用 context 的例子。

    Context Provider:

    1. import { createContext } from "react";
    2. export const UserContext = createContext();
    3. export const UserActionsContext = createContext();

    在父组件中,向消费者提供了 UserContextUserActionsContext

    1. import { Component, createContext } from "react";
    2. import ContextApiClassConsumer from "./ContextApiClassConsumer.jsx";
    3. import { UserContext, UserActionsContext } from "./userContext.js";
    4. class ContextApiHooksProvider extends Component {
    5. state = {
    6. user: {
    7. name: "Class",
    8. },
    9. };
    10. setUser = user => this.setState({ user });
    11. render() {
    12. return (
    13. <UserContext.Provider value={this.state.user}>
    14. <UserActionsContext.Provider value={this.setUser}>
    15. <ContextApiClassConsumer />
    16. </UserActionsContext.Provider>
    17. </UserContext.Provider>
    18. );
    19. }
    20. }
    21. export default ContextApiHooksProvider;

    这里 ContextApiClassConsumer 组件就可以获取到父组件提供的usersetUser

    Context Consumer:

    1. import { Component } from "react";
    2. import { UserContext, UserActionsContext } from "./userContext.js";
    3. class ContextApiClassConsumer extends Component {
    4. render() {
    5. return (
    6. <UserContext.Consumer>
    7. {user => (
    8. <UserActionsContext.Consumer>
    9. {setUser => (
    10. <div>
    11. <input
    12. type="text"
    13. value={user.name}
    14. onChange={e =>
    15. setUser({
    16. name: e.target.value,
    17. })
    18. }
    19. />
    20. </div>
    21. )}
    22. </UserActionsContext.Consumer>
    23. )}
    24. </UserContext.Consumer>
    25. );
    26. }
    27. }
    28. export default ContextApiClassConsumer;

    在上面的例子中,UserContext.Consumer 组件的子函数接收 user 状态,UserActionsContext.Consumer 的子函数接收 setUser 方法。

    使用 Hooks 实现和上面的代码非常类似,但是会更简洁。同样,我们使用 UserContext.ProviderUserActionsContext.Provider 组件来提供 user 状态和 setUser 方法。

    Context Provider:

    1. import { useState } from "react";
    2. import ContextApiHooksConsumer from "./ContextApiHooksConsumer.jsx";
    3. import { UserContext, UserActionsContext } from "./userContext.js";
    4. const ContextApiHooksProvider = () => {
    5. const [user, setUser] = useState({
    6. name: "Hooks",
    7. });
    8. return (
    9. <UserContext.Provider value={user}>
    10. <UserActionsContext.Provider value={setUser}>
    11. <ContextApiHooksConsumer />
    12. </UserActionsContext.Provider>
    13. </UserContext.Provider>
    14. );
    15. };
    16. export default ContextApiHooksProvider;

    在函数组件中,我们可以像在类组件中一样使用 context,但是,hooks 中有一种更简洁的方法,我们可以利用 useContext hook 来访问 context 值。

    Context Consumer:

    1. import { useContext } from "react";
    2. import { UserContext, UserActionsContext } from "./userContext.js";
    3. const ContextApiHooksConsumer = () => {
    4. const user = useContext(UserContext);
    5. const setUser = useContext(UserActionsContext);
    6. return (
    7. <div>
    8. <input
    9. type="text"
    10. value={user.name}
    11. onChange={e =>
    12. setUser({
    13. name: e.target.value,
    14. })
    15. }
    16. />
    17. </div>
    18. );
    19. };
    20. export default ContextApiHooksConsumer;

    7. 跨重新渲染保留值

    在某些情况下,我们可能需要再组件中存储一些数据。但是不希望将其存储在状态中,因为 UI 不以任何方式依赖这些数据。

    例如,我们可能会保存一些希望稍后包含在 API 请求中的元数据。这在类组件中很容易实现,只需为类分配一个新属性即可。

    1. import { Component } from "react";
    2. class PreservingValuesClass extends Component {
    3. state = {
    4. counter: 0,
    5. };
    6. componentDidMount() {
    7. this.valueToPreserve = Math.random();
    8. }
    9. showValue = () => {
    10. alert(this.valueToPreserve);
    11. };
    12. increment = () => this.setState(({ counter }) => ({ counter: counter + 1 }));
    13. render() {
    14. return (
    15. <div>
    16. <p>Counter: {this.state.counter}</p>
    17. <button onClick={this.increment}>Increment</button>
    18. <button onClick={this.showValue}>Show</button>
    19. </div>
    20. );
    21. }
    22. }
    23. export default PreservingValuesClass;

    在这个例子中,当组件被挂载时,我们在 valueToPreserve 属性上分配了一个动态随机数。除此之外,还有 increment 方法来强制重新渲染,但是Show按钮时会弹窗显示保留的值。

    这在类组件中很容易实现,但是在函数组件中就没那么简单了。这是因为,任何时候函数组件的重新渲染都会导致函数中的所有内容重新执行。这意味着如果我们有这样的组件:

    1. const MyComponent = props => {
    2. const valueToPreserve = Math.random()
    3. // ...
    4. }

    组件每次重新渲染时都会重新调用 Math.random() 方法,因此创建的第一个值将丢失。

    避免此问题的一种方法是将变量移到组件之外。 但是,这是行不通的,因为如果该组件被多次使用,则该值会将被它们中的每一个覆盖。

    恰好,React 提供了一个非常适合这个用例的 hook。 我们可以通过使用 useRef hook 来保留函数组件中重新渲染的值。

    1. import { useState, useRef, useEffect } from "react";
    2. const PreserveValuesHooks = props => {
    3. const valueToPreserve = useRef(null);
    4. const [counter, setCounter] = useState(0);
    5. const increment = () => setCounter(counter => counter + 1);
    6. const showValue = () => {
    7. alert(valueToPreserve.current);
    8. };
    9. useEffect(() => {
    10. valueToPreserve.current = Math.random();
    11. }, []);
    12. return (
    13. <div>
    14. <p>Counter: {counter}</p>
    15. <button onClick={increment}>Increment</button>
    16. <button onClick={showValue}>Show value</button>
    17. </div>
    18. );
    19. };
    20. export default PreserveValuesHooks;

    valueToPreserve 是一个初始值为 nullref。 但是,它后来在 useEffect 中更改为我们想要保留的随机数。

    8. 如何向父组件传递状态和方法?

    尽管我们不应该经常访问子组件的状态和属性,但是在某些情况下它可能会很有用。例如,我们想要重置某些组件的状态或者访问它的状态。我们需要创建一个 Ref,可以在其中存储对想要访问的子组件的引用。在类组件中,可以使用 createRef 方法,然后将该 ref 传递给子组件。

    父组件:

    1. import { Component, createRef } from "react";
    2. import ExposePropertiesClassChild from "./ExposePropertiessClassChild";
    3. class ExposePropertiesClassParent extends Component {
    4. constructor(props) {
    5. super(props);
    6. this.childRef = createRef();
    7. }
    8. showValues = () => {
    9. const counter = this.childRef.current.state.counter;
    10. const multipliedCounter = this.childRef.current.getMultipliedCounter();
    11. alert(`
    12. counter: ${counter}
    13. multipliedCounter: ${multipliedCounter}
    14. `);
    15. };
    16. increment = () => this.setState(({ counter }) => ({ counter: counter + 1 }));
    17. render() {
    18. return (
    19. <div>
    20. <button onClick={this.showValues}>Show</button>
    21. <ExposePropertiesClassChild ref={this.childRef} />
    22. </div>
    23. );
    24. }
    25. }
    26. export default ExposePropertiesClassParent;

    子组件:

    1. import { Component } from "react";
    2. class ExposePropertiesClassChild extends Component {
    3. state = {
    4. counter: 0,
    5. };
    6. getMultipliedCounter = () => {
    7. return this.state.counter * 2;
    8. };
    9. increment = () => this.setState(({ counter }) => ({ counter: counter + 1 }));
    10. render() {
    11. return (
    12. <div>
    13. <p>Counter: {this.state.counter}</p>
    14. <button onClick={this.increment}>Increment</button>
    15. </div>
    16. );
    17. }
    18. }
    19. export default ExposePropertiesClassChild;

    要访问子组件的属性,只需要在父组件中创建一个 ref 并传递它。 现在,让我们看看如何使用函数组件和 hook 来实现相同的目标。

    父组件:

    1. import { useRef } from "react";
    2. import ExposePropertiesHooksChild from "./ExposePropertiesHooksChild";
    3. const ExposePropertiesHooksParent = props => {
    4. const childRef = useRef(null);
    5. const showValues = () => {
    6. const counter = childRef.current.counter;
    7. const multipliedCounter = childRef.current.getMultipliedCounter();
    8. alert(`
    9. counter: ${counter}
    10. multipliedCounter: ${multipliedCounter}
    11. `);
    12. };
    13. return (
    14. <div>
    15. <button onClick={showValues}>Show child values</button>
    16. <ExposePropertiesHooksChild ref={childRef} />
    17. </div>
    18. );
    19. };
    20. export default ExposePropertiesHooksParent;

    在父组件中,我们使用 useRef hook 来存储对子组件的引用。 然后在 showValues 函数中访问 childRef 的值。 可以看到,这里与类组件中的实现非常相似。

    子组件:

    1. import { useState, useImperativeHandle, forwardRef } from "react";
    2. const ExposePropertiesHooksChild = (props, ref) => {
    3. const [counter, setCounter] = useState(0);
    4. const increment = () => setCounter(counter => counter + 1);
    5. useImperativeHandle(ref, () => {
    6. return {
    7. counter,
    8. getMultipliedCounter: () => counter * 2,
    9. };
    10. });
    11. return (
    12. <div>
    13. <p>Counter: {counter}</p>
    14. <button onClick={increment}>Increment</button>
    15. </div>
    16. );
    17. };
    18. export default forwardRef(ExposePropertiesHooksChild);

    forwardRef 将从父组件传递的 ref 转发到组件,而 useImperativeHandle 指定了父组件应该可以访问的内容。

    9. 小结

    通过这篇文章,相信你对使用Hooks(函数组件)来重构类组件有了一定了解。Hooks 的出现使得 React 代码更加简洁,并且带来了更好的状态逻辑可重用性。在开始编写 Hooks 之前,建议先阅读 React Hooks 的官方文档,因为在编写时需要遵循某些规则,例如不要改变 hooks 的调用顺序。

    以太坊cppgolang区别 编程

    以太坊cppgolang区别

    以太坊是一种去中心化的开源平台,它采用智能合约技术,旨在构建和运行不受干扰的分布式应用程序。作为目前最受欢迎的区块链平台之一,以太坊提供了多种编程语言的支持,其
    progolang 编程

    progolang

    Go语言(Golang)是由Google开发的一门静态类型编程语言。作为一名专业的Golang开发者,我深知这门语言的优势和特点。在本文中,我将介绍Golang
    golangn个发送者 编程

    golangn个发送者

    Golang是一种开源的编程语言,由Google团队开发,旨在提高程序的并发性和简化软件开发过程。在Go语言中,有时需要向多个接收者发送信息。本文将介绍如何在G
    golang技能图谱 编程

    golang技能图谱

    从互联网行业的快速发展到人工智能技术的日益成熟,各种编程语言也应运而生。而在这众多的编程语言中,Golang(即Go)作为一门强大且高效的开发语言备受关注。Go
    评论:0   参与:  8