An warware: react-dom

React-DOM wani muhimmin bangare ne na yanayin yanayin React, kamar yadda manne ne ke haษ—a abubuwan siffanta React zuwa ainihin DOM a cikin burauzar gidan yanar gizo ko wani dandamali kamar React Native. Za mu zurfafa zurfi cikin fahimtar React-DOM mafi kyau da kuma yadda yake taimakawa sauฦ™aฦ™e aiki mai sauฦ™i na aikace-aikacen React.

Laburaren React-DOM yana ba da takamaiman hanyoyin DOM waษ—anda za a iya amfani da su a saman matakin aikace-aikacen React don ba da damar ingantacciyar hanyar sarrafa sabuntawa ga DOM. Wannan yana haษ“aka ฦ™arfin aikace-aikacen da lokacin amsawa, yana mai da shi mafi kyawun mai amfani.

import React from 'react';
import ReactDOM from 'react-dom';

function App() {
  return (
    <h1>Hello, world!</h1>
  );
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

Snippet na sama na code yana nuna aikace-aikacen Sannu Duniya ta amfani da React-DOM, inda hanyar ReactDOM.render ke ษ—aukar mahawara guda biyu - ษ“angaren amsa don sabunta DOM tare da akwati don ษ—aukakawa.

Hanyoyin React-DOM

React-DOM da farko yana ba da hanyoyi biyu; sa kuma cireComponentAtNode.

  • ReactDOM.render(): Wannan ita ce hanyar da aka fi amfani da ita ta hanyar ษ—akin karatu na React-DOM. Yana mayar da kashi na React a cikin kullin DOM da aka tanadar a cikin mai binciken kuma ya dawo da batun sashin da aka yi ko kuma ya dawo da ษ“arna don abubuwan da ba su da ฦ™asa.
ReactDOM.render(element, container[, callback])
  • ReactDOM.unmountComponentAtNode(): Wannan hanyar tana cire abin da aka ษ—ora na React daga DOM kuma yana tsaftace masu gudanar da taronsa da jihar.
ReactDOM.unmountComponentAtNode(container)

Virtual DOM a cikin React

ฦŠaya daga cikin mahimman ra'ayoyin da ke bayan React shine amfani da Virtual DOM. Ainihin kwafin nauyi ne na ainihin DOM da aka adana a ฦ™waฦ™walwar ajiya. React-DOM shine ษ—akin karatu wanda ke kwatanta Virtual DOM na yanzu tare da sigar gaba kuma yana haifar da jerin canje-canjen da za a yi amfani da su a ainihin DOM, tsarin da aka sani da "diffing". Bayan yin rarrabuwar kawuna, React yana ba da waษ—annan canje-canje kuma yana amfani da su zuwa ainihin DOM don ingantaccen aiki, tsarin da aka sani da โ€œslsuwa.โ€

Fahimtar da aiki yadda ya kamata tare da React-DOM yana buฦ™atar sanin gabaษ—ayan gine-ginen React. Don haษ“aka ฦ™arfin React da gaske, masu haษ“akawa suna buฦ™atar sanin muhimmiyar rawar da React-DOM ke takawa wajen haษ—a yanayin React tare da ingantaccen gabatarwar gidan yanar gizo. A zahiri, ainihin React na iya kwance a cikin abubuwan haษ—in gwiwa da kwararar bayanai ta hanya ษ—aya, amma ainihin sihirin yana faruwa godiya ga ษ—akin karatu na React-DOM.

Shafi posts:

Leave a Comment