- Serverless Web Applications with React and Firebase
- Harmeet Singh Mayur Tanna
- 155字
- 2021-08-27 19:11:09
The componentDidCatch() method
This method allows us to catch the JavaScript errors in React Components. We can log those errors and display another fallback UI instead of the component tree that crashed.
Now we have a clear idea about component methods that are available in React Components.
Observe the following JavaScript code snippet:
<section>
<h2>My First Example</h2>
</section>
<script>
var root = document.querySelector('section').createShadowRoot();
root.innerHTML = '<style>h2{ color: red; }</style>' +'<h2>Hello World!</h2>';
</script>
Now, observe the following ReactJS code snippet:
var sectionStyle = {
color: 'red'
};
var MyFirstExample = React.createClass({
render: function() {
return (<section><h2 style={sectionStyle}>
Hello World!</h2></section>
)}
})
ReactDOM.render(<MyFirstExample />, renderedNode);
Now, after observing the preceding examples of React and JavaScript, we will have a clear idea of normal HTML encapsulation and ReactJS custom HTML tags.
React isn't an MVC framework; it's a library for building a composable user interface and reusable components. React is used at Facebook in its production stages and instagram.com is entirely built on React.
推薦閱讀
- Learning Scala Programming
- Learning Single:page Web Application Development
- Visual C++程序設計教程
- Android應用程序開發與典型案例
- C語言程序設計習題解析與上機指導(第4版)
- Python入門很簡單
- 實用防銹油配方與制備200例
- Linux網絡程序設計:基于龍芯平臺
- Mastering Xamarin.Forms(Second Edition)
- Vue.js 2 Web Development Projects
- Android移動應用開發項目教程
- 零基礎C#學習筆記
- C/C++代碼調試的藝術(第2版)
- Keil Cx51 V7.0單片機高級語言編程與μVision2應用實踐
- Zend Framework 2 Cookbook