Skip to content

Instantly share code, notes, and snippets.

View robzlabz's full-sized avatar
🐳
Working from home

Robbyn Rahmandaru robzlabz

🐳
Working from home
  • RobzLabz Software Technology
  • Yogyakarta, Indonesia
View GitHub Profile
import React from "react";
// di functional component menggunakan useEffect dengan argumen kedua [] array kosong
const FunctionalComponent = () => {
React.useEffect(() => {
console.log("Aku Dijalankan");
}, []);
return <h1>Halo, Selamat Pagi</h1>;
};
onClick={() =>
this.setState((state) => {
return {
...state,
count: state.count + 1
};
})
}
class CounterComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0
};
}
render() {
return (
@robzlabz
robzlabz / HandlingStateFunctionalComponent.jsx
Created January 7, 2021 05:36
Handling State di Functional Component
const CounterComponent = () => {
const [count, setCount] = React.useState(0);
return (
<div>
<p>Sudah di click: {count} kali</p>
<button onClick={() => setCount(count + 1)}>Click Saya</button>
</div>
);
};
class Card extends React.Component {
render() {
const { name } = this.props;
return <h1>Hello, { name }</h1>;
}
// atau 👇
render() {
return <h1>Hello, { this.props.name }</h1>;
// Pemanggilan
<Card name="Agus"/>
const Card = (props) => {
return <h1>Hai, {props.name}</h1>;
};
// atau bisa di pecah langsung menggunakan object desctructure
// jadi kita bisa langsung memanggil 'name' tanpa variable props
import React, { Component } from "react";
class ClassComponent extends Component {
render() {
return <h1>JSX di dalam fungsi render component</h1>;
}
}
/// atau 👇
import React from "react";
const KomponenFungsi = () => {
return <h1>Halo, Ini dibuat dengan Functional Component</h1>;
};
/// atau 👇
function KomponenFungsiBentukLain() {
return <h1>Halo, ini komponen fungsi</h1>;
@robzlabz
robzlabz / index.js
Created July 8, 2020 22:57
Menambahkan Field
const User = mongoose.model('User', new mongoose.Schema({
username: String,
password: String,
about: String,
joinAt: Date,
points: Number
}))
@robzlabz
robzlabz / index.js
Created July 8, 2020 22:50
Admin Bro Mongoose Example
const AdminBro = require('admin-bro')
const AdminBroExpress = require('admin-bro-expressjs')
const AdminBroMongoose = require('admin-bro-mongoose')
const express = require('express')
const app = express()
AdminBro.registerAdapter(AdminBroMongoose)
const mongoose = require('mongoose')