React 16 提供了一个内置的函数componentDidCatch, 它会在render抛出异常的时候运行。
官方的示例代码如下:
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
// left: 37, up: 38, right: 39, down: 40, | |
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36 | |
var keys = {37: 1, 38: 1, 39: 1, 40: 1}; | |
function preventDefault(e) { | |
e = e || window.event; | |
if (e.preventDefault) | |
e.preventDefault(); | |
e.returnValue = false; |
'use strict'; | |
/** | |
* @param {Number} [baseFontSize = 100] - 基础fontSize, 默认100px; | |
* @param {Number} [fontscale = 1] - 有的业务希望能放大一定比例的字体; | |
*/ | |
const win = window; | |
export default win.flex = (baseFontSize, fontscale) => { | |
const _baseFontSize = baseFontSize || 100; | |
const _fontscale = fontscale || 1; |
<?php | |
/** | |
* Plugin Name: WordPress Importer Post ID Preservation | |
* Description: When importing posts make sure that post ID from the original site is used on the destination site. This should only be used when first setting up an environment, or if the destination site is not canonical (e.g. a dev or staging environment). | |
* Author: Weston Ruter, XWP | |
*/ | |
/** | |
* Force WordPress Importer to never honor the post_exists() check, since we want to override existing posts. | |
* |
import React, {Component} from 'react'; | |
import { | |
Animated, | |
Platform, | |
StatusBar, | |
StyleSheet, | |
Text, | |
View, | |
RefreshControl, | |
ScrollView, |
add the following to your theme’s functions.php file:
function remove_devicepx() {
wp_dequeue_script( 'devicepx' );
}
add_action( 'wp_enqueue_scripts', 'remove_devicepx' );
## angular2里的路由模块支持多层嵌套路由,不需要像angular1那样使用第三方的路由了。
具体配置如下:
const routes: Routes = [
{path: '', component: IndexComponent},
{path: 'home', component: HomeComponent},
{path: 'about', component: AboutComponent }//redirectTo: 'about/about1'
];
Ever since we started using React to rebuild our UI at uberVU (now Hootsuite) the #1 developer question has probably been:
What's the exact difference between props and state?
It's fairly easy to understand how they work—especially when seen in context—but it's also a bit difficult to grasp them conceptually. It's confusing at first because they both have abstract terms and their values look the same, but they also have very different roles.