Do I need to leave the time off on the server response and have the client render that afterwards?
Unfortunately yes.
You can build a utility component to make this less tedious.
Class component:
// utility
import React, { Component } from 'react';
// Class component
export default class ClientRender extends Component {
state = { isMounted: false };
componentDidMount () {
this.setState({ isMounted: true });
}
render () {
const { children } = this.props;
const { isMounted } = this.state;
return isMounted ? children : null;
}
}
// Function component
export default function ClientRender({ children }) {
const [isMounted, setIsMounted] = React.useState(false);
React.useEffect(() => {
setIsMounted(true);
}, []);
return isMounted ? children : null;
}
// in your app
import React from 'react';
import moment from 'moment';
import ClientRender from './path/to/client-render';
export default function MyComponent (props) {
return (
<div>
<ClientRender>{moment(props.timeUTC * 1000).format('LLL')}</ClientRender>
</div>
);
}