Skip to content

Instantly share code, notes, and snippets.

View ebrugulec's full-sized avatar
💃

Ebru Gulec ebrugulec

💃
  • Berlin, Germany
View GitHub Profile
import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
function Reddit() {
const [posts, setPosts] = useState([]);
useEffect(async () => {
const res = await fetch(
"https://www.reddit.com/r/reactjs.json"
);
function Reddit({ subreddit }) {
const [posts, setPosts] = useState([]);
useEffect(async () => {
const res = await fetch(
`https://www.reddit.com/r/${subreddit}.json`
);
const json = await res.json();
setPosts(json.data.children.map(c => c.data));
function App() {
const [inputValue, setValue] = useState("reactjs");
const [subreddit, setSubreddit] = useState(inputValue);
const handleSubmit = e => {
e.preventDefault();
setSubreddit(inputValue);
};
return (
mkdir react-rate-component
cd react-rate-component
npm init
npm i react react-dom webpack webpack-cli webpack-dev-server html-webpack-plugin style-loader css-loader babel-core babel-loader@7.1.4 babel-preset-env babel-preset-react -D
{
"name": "react-rate-component",
"version": "1.0.0",
"description": "react rating component with custom symbol",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
/*** src/index.js ***/
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
/*** import './styles.css'; ***/
function ReactRateComponent(props){
return(
...
)
}
/*** examples/src/index.html ***/
<html>
<head>
<title>React Rate Component</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" type="image/png" href="/favicon.png"/>
</head>
<body>
<noscript>
/*** examples/src/index.js ***/
import React from 'react';
import { render} from 'react-dom';
import ReactRateComponent from '../../src';
const App = () => (
<ReactRateComponent />
);
render(<App />, document.getElementById("root"));
/*** webpack.config.js ***/
const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const htmlWebpackPlugin = new HtmlWebpackPlugin({
template: path.join(__dirname, "examples/src/index.html"),
filename: "./index.html"
});
module.exports = {
entry: path.join(__dirname, "examples/src/index.js"),
module: {