preact#Component JavaScript Examples
The following examples show how to use
preact#Component.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: withMobileDetection.js From lockdown with Apache License 2.0 | 6 votes |
export default function withMobileDetection(WrappedComponent) {
return class extends Component {
constructor(props) {
super(props);
this.state = {
isMobile: false,
daysRange: 70,
};
}
componentWillMount() {
let width = window.innerWidth || window.clientWidth;
let isMobile = false;
let daysRange = 80;
if (width <= 960) {
isMobile = true;
daysRange = 70;
}
this.setState({
isMobile,
daysRange,
});
}
render(_) {
return html`<${WrappedComponent} isMobile=${this.state.isMobile} daysRange=${this.state.daysRange} ...${this.props} />`;
}
};
}
Example #2
Source File: serializer.test.jsx From jest-preset-preact with MIT License | 6 votes |
describe('serializer', () => { it('should serialize simple component', () => { const App = () => <div>foo</div>; expect(<App />).toMatchSnapshot(); }); it('should serialize nested component', () => { const Bar = () => <div>Bar</div>; const App = () => ( <div> <Bar /> foo </div> ); expect(<App />).toMatchSnapshot(); }); it('should class components', () => { class App extends Component { render() { return <div />; } } expect(<App />).toMatchSnapshot(); }); });
Example #3
Source File: Lazy.js From lockdown with Apache License 2.0 | 5 votes |
async componentWillMount() {
const module = await this.props.component();
const Component = module.default || module;
this.setState({ Component });
}
Example #4
Source File: Lazy.js From lockdown with Apache License 2.0 | 5 votes |
render({ props }, { Component }) {
return h(Component, props);
}