question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Class Component example?

See original GitHub issue

Great library! I actually prefer having all the pages is JSON-ish format, plus you get the benefits of react-loadable built in which is perfect.

I was trying this out and wanted to see if there’s an example of a route which uses a react class component instead of a function.

So instead of

// pages/reference.js
import * as React from 'react'

export default function Reference() {
  return (
    <div>
      <h2>Reference</h2>
    </div>
  )
}

What would be the createPage syntax for this:

import React from 'react'

export default class Reference extends React.Component {
  render() {
    return <h2>Smart Page!</h2>;
  }
}

Thank you!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jamesknelsoncommented, Feb 3, 2019

Have just merged this change, so that content properties that are functions will now be treated as function components, and have a route property passed in.

This will be part of 0.11, which should be released soon after React 16.8 is (with hooks support).

1reaction
jamesknelsoncommented, Dec 17, 2018

I’ve just made a change to allow this and released it with react-navi 0.9. You can see a demo here:

https://frontarm.com/demoboard/?id=ec703f64-fa4f-4110-9323-8c46de76186f

Previously, if <NavRoute /> saw a function in route.content, it would call it to get the rendered element. I’ve kept this behavior for plain functions, but now it’ll check to see if the content is a class component and create an element if it is, passing through the Route object as props.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Class Components - W3Schools
When creating a React component, the component's name must start with an upper case letter. The component has to include the extends React.Component...
Read more >
Components and Props - React
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to...
Read more >
ReactJS Class Based Components - GeeksforGeeks
React class based components are the bread and butter of most modern web apps built in ReactJS. These components are simple classes (made...
Read more >
The Best React Examples - freeCodeCamp
React Component Example ... Components are reusable in React.js. You can inject value into props as given below: function Welcome(props) { return ...
Read more >
Component State: React State Cheatsheet - Codecademy
React class components store their state as a JavaScript object. This object is initialized in the component's constructor() . In the example, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found