This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyComponent = React.memo(function MyComponent(props) { | |
/* only rerenders if props change */ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyComponent(props) { | |
/* render using props */ | |
} | |
function areEqual(prevProps, nextProps) { | |
/* | |
return true if passing nextProps to render would return | |
the same result as passing prevProps to render, | |
otherwise return false | |
*/ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {lazy, Suspense} from 'react'; | |
const OtherComponent = lazy(() => import('./OtherComponent')); | |
function MyComponent() { | |
return ( | |
<Suspense fallback={<div>Loading...</div>}> | |
<OtherComponent /> | |
</Suspense> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lazy component | |
import { lazy } from 'react'; | |
const OtherComponent = lazy(() => import('./OtherComponent')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyContext = React.createContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass extends React.Component { | |
static contextType = MyContext; | |
componentDidMount() { | |
let value = this.context; | |
/* perform a side-effect at mount using the value of MyContext */ | |
} | |
componentDidUpdate() { | |
let value = this.context; | |
/* ... */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static getDerivedStateFromError(error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ErrorBoundary extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { hasError: false }; | |
} | |
static getDerivedStateFromError(error) { | |
// Update state so the next render will show the fallback UI. | |
return { hasError: true }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cdk-virtual-scroll-viewport itemSize="50" class="example-viewport"> | |
<div *cdkVirtualFor="let item of items" class="example-item">{{item}}</div> | |
</cdk-virtual-scroll-viewport> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ChangeDetectionStrategy, Component} from '@angular/core'; | |
/** @title Basic virtual scroll */ | |
@Component({ | |
selector: 'cdk-virtual-scroll-overview-example', | |
styleUrls: ['cdk-virtual-scroll-overview-example.css'], | |
templateUrl: 'cdk-virtual-scroll-overview-example.html', | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
}) | |
export class CdkVirtualScrollOverviewExample { |
OlderNewer