React Component Extensions

After React mounts the app and init Framework7, we will have access to Framework7’s initialized instance and some other useful properties that will be available in all React components (Class components):

Components Properties

this.$f7readyCallback function that will be executed when Framework7 fully intialized. Useful to use in components when you need to access Framework7 API and to be sure it is ready. So it is safe to put all Framework7 related logic into this callback. As an argument it receives initialized Framework7 instance. For example:
  1. export default class extends React.Component {
  2. render() {
  3. },
  4. componentDidMount() {
  5. this.$f7ready((f7) => {
  6. f7.dialog.alert(‘Component mounted’);
  7. });
  8. },
  9. };
this.$f7Main Framework7’s initialized instance. It allows you to use any of Framework7 APIs
this.$$
this.Dom7
Access to built-in Dom7 DOM library that utilizes most edge and high-performance methods for DOM manipulation
this.$deviceAccess to Device utilities
this.$requestAccess to Request library for XHR requests
this.$utilsAccess to Utils object with few useful utilities
this.$themeObject with boolean properties with information about currently used theme (iOS or MD): this.$theme.ios and this.$theme.material
this.$f7router

This property only available for components loaded with router (e.g. pages, routable modals, routable tabs). If you need to access this property in “deeper” child components, then you need to pass it down using props.

Framework7 Router Instance. It has a lot of useful Methods & Properties to use for navigation

this.$f7route

This property only available for components loaded with router (e.g. pages, routable modals, routable tabs). If you need to access this property in “deeper” child components, then you need to pass it down using props.

Object with current route data that was used to load this page, tab or modal. It has the following properties

  • url - route URL
  • path - route path
  • query - object with route query. If the url is /page/?id=5&foo=bar then it will contain the following object {id: ‘5’, foo: ‘bar’}
  • params - route params. If we have matching route with /page/user/:userId/post/:postId/ path and url of the page is /page/user/55/post/12/ then it will be the following object {userId: ‘55’, postId: ‘12’}
  • name - route name
  • hash - route URL hash
  • route - object with matching route from available routes
  • context - context that was passed to the route

Phenome.js

Framework7-React components are build with Phenome.js, so they are empowered with some extra features like Slots and Events.

Slots

All Framework7-React components use slots to distribute children across component structure. They work exactly the same as Web Component Slots and Vue.js Slots.

For example

  1. export default () => (
  2. <Page>
  3. <p slot="fixed">I'm fixed page element</p>
  4. <p>I'm in scrollable page area</p>
  5. <List>
  6. <ListItem>
  7. <img slot="media" src="path/to/image.png" />
  8. <span slot="title">Title 1</span>
  9. <span slot="title">Title 2</span>
  10. </ListItem>
  11. </List>
  12. </Page>
  13. )

Renders to:

  1. <div class="page">
  2. <p slot="fixed">I'm fixed page element</p>
  3. <div class="page-content">
  4. <p>I'm in scrollable page area</p>
  5. <div class="list">
  6. <ul>
  7. <li>
  8. <div class="item-content">
  9. <div class="item-media">
  10. <img slot="media" src="path/to/image.png" />
  11. </div>
  12. <div class="item-inner">
  13. <div class="item-title">
  14. <span slot="title">Title 1</span>
  15. <span slot="title">Title 2</span>
  16. </div>
  17. </div>
  18. </div>
  19. </li>
  20. </ul>
  21. </div>
  22. </div>
  23. </div>

Events

All Framework7-React components support events, which are actually props, and their listeners must be assigned as on$Event prop.

For example <Page> component supports pageInit, pageBeforeIn and other events, so to handle such events:

  1. export default class extends React.Component {
  2. render() {
  3. return (
  4. <Page onPageBeforeIn={this.onPageBeforeIn.bind(this)} onPageInit={this.onPageInit.bind(this)}>
  5. ...
  6. </Page>
  7. )
  8. }
  9. onPageBeforeIn() {
  10. // do something on page before in
  11. }
  12. onPageInit() {
  13. // do something on page init
  14. }
  15. }