Skip to content

Instantly share code, notes, and snippets.

View sabesansathananthan's full-sized avatar
:octocat:
Work

Sathananthan Sabesan sabesansathananthan

:octocat:
Work
View GitHub Profile
@sabesansathananthan
sabesansathananthan / App.test.js
Created November 7, 2019 14:11
test file example for React Best practice
import React from 'react'
import ReactDom from 'react-dom'
import App from '.'
it('renders without crashing', () => {
const div = document.createElement{'div'};
ReactDOM.render(<App/ >, div);
ReactDOM.unmountComponentAtNode(div);
});
@sabesansathananthan
sabesansathananthan / SateInsideConstructor.js
Created November 8, 2019 09:07
This is an example for react best practice
class SateInsideConstructor extends React.Component {
constructor(props) {
super(props)
this.state = {
counter: 0
}
}
/* your logic */
}
@sabesansathananthan
sabesansathananthan / ClassFieldState.js
Last active March 10, 2020 19:40
This is an example for React best practice article
import React from 'react'
class MyComponent extends React.Component {
state = {
counter: 0
}
/* your logic */
}
@sabesansathananthan
sabesansathananthan / ModalButton.js
Created December 4, 2019 08:39
React best Practice default props example
import React, { Component } from "react";
import { Button } from "react-bootstrap";
import PropTypes from 'prop-types'
class ModalButton extends Component {
render() {
return <Button variant={this.props.variant}>{this.props.children}</Button>;
}
}
@sabesansathananthan
sabesansathananthan / slider.js
Last active March 10, 2020 19:41
Embed Medium as a blog on your React Website
import React from 'react';
import { Col, Row } from 'shards-react';
import MediumCard from './MediumCard';
// wrapper for items
class Slider extends React.Component {
constructor(props) {
super(props);
this.state = { itemRows: [], avatar: '', profileLink: '' };
@sabesansathananthan
sabesansathananthan / Totext.js
Last active August 17, 2020 18:35
Embed a blog on your React Website
export default function ToText(node) {
let tag = document.createElement("div");
tag.innerHTML = node;
node = tag.innerText;
return node;
}
@sabesansathananthan
sabesansathananthan / ShortenText.js
Last active August 17, 2020 18:37
Embed a blog on your React Website
export default function ShortenText(text, startingPoint, maxLength) {
return text.length > maxLength
? text.slice(startingPoint, maxLength)
: text;
}
@sabesansathananthan
sabesansathananthan / MediumCard.js
Last active March 10, 2020 19:44
Embed Medium as a blog on your React Website
import React from 'react';
import { Card, CardBody } from 'shards-react';
import ShortenText from '../utils/ShortenText';
import ToText from '../utils/ToText';
import { faUser, faCalendarAlt } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
// functional card component to display single item
export default function MediumCard(props) {
var shortMonthName = new Intl.DateTimeFormat('en-US', {
month: 'short'
@sabesansathananthan
sabesansathananthan / App.js
Last active August 17, 2020 18:41
Embed a blog on your React Website
import React from 'react';
import Slider from './Slider';
import { Col } from 'shards-react';
function App() {
return (
<React.Fragment>
<Col xs="12" sm="4" className="text-sm-left text-center text-md-left mb-sm-0">
<span className="text-uppercase page-subtitle">Components</span>
<h3 className="page-title">Posts</h3>
@sabesansathananthan
sabesansathananthan / initMaps.js
Last active April 30, 2020 02:46
How to use the Google Maps API with Custom styling in React.js
export class Maps extends React.Component {
render() {
const mapStyles = {
width: "100%",
height: "100%",
};
return (
<Map
google={this.props.google}
zoom={15}