4 ms·
the rise of FrontBackend Engineers
by yieldcrv 4y ago
the rise of FrontBackend Engineers
- basicallybones 4y ago// frontbackend engineering tutorial import React from 'react'; import { UsersService } from './users.service'; import { registerRoute } from 'react-backend-router'; export class UsersController extends React.Component { constructor(props) { super(props); this.state = { createUserPayload: null, updateUserPayload: null } this.createUser = this.createUser.bind(this); this.updateUser = this.updateUser.bind(this); } componentDidMount() { registerRoute({ path: '/users', method: 'POST', handler: this.createUser }); registerRoute({ path: '/users', method: 'PUT', handler: this.updateUser }); } createUser() { const { req } = this.props; const { body } = req; this.setState({ createUserPayload: { name: body.name } }); } updateUser() { const { req } = this.props; const { body } = req; this.setState({ updateUserPayload: { name: body.name } }); } render() { const { createUserPayload, updateUserPayload } = this.state; return ( <UsersService create={createUserPayload} update={updateUserPayload} /> ) } }