remoteinterview / zero

Zero is a web server to simplify web development.

Home Page:https://zeroserver.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React time example not working

3goats opened this issue · comments

Hi,

Just followed the first part of the tutorial.

The API is working and returning the time as expected.

// time.js
const moment = require("moment")
module.exports = (req, res) => {
  var time = moment().format('LT');   // 11:51 AM
  res.send({time: time })
}

Its returning {"time":"2:47 PM"}

However this is not working. It's only rendering Current time is: and not rendering the this.props.time data. There are no errors in the console or on the server.

// index.jsx
import React from 'react'
export default class extends React.Component {
  static async getInitialProps(){
    var json = await fetch("/time").then((resp) => resp.json())
    console.log("hello")
    return {time: json.time}
  }
  render() {
    return <p>Current time is:: {this.props.time}</p>
  }
}

Server output is and both routes are showing ready.

success Saved lockfile.
zero
⚡️ Zero v1.1.19
⬇️  Updating packages
yarn install v1.22.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...

success Saved lockfile.
✨  Done in 5.28s.
✔ Server running on http://localhost:3000
✔ / ready
✔ /time ready

Updated node to latest

Hi, can you tell me what node version didn't work? I will have a look.