This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Author: Alok Ranjan Daftuar | |
// App.js | |
// | |
import React from 'react'; | |
import List from './components/List'; | |
import WithLoading from './components/withLoading.js'; | |
// | |
const ListWithLoading = WithLoading(List); | |
class App extends React.Component { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// withStyle.js | |
//Author: Alok Ranjan Daftuar | |
// | |
const withStyle = (BaseComponent) => (props) => | |
<BaseComponent {...props} style={{ fontWeight: 700, color: "blue" }} />; | |
export default withStyle; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// withAuth.js | |
//Author: Alok Ranjan Daftuar | |
// | |
import React from "react"; | |
export function withAuth(Component) { | |
return class AuthenticatedComponent extends React.Component { | |
isAuthenticated() { | |
return this.props.isAuthenticated; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SayHelloComponent.js | |
//Author: Alok Ranjan Daftuar | |
// | |
const SayHelloComponent = ({ name, ...otherProps }) => ( | |
<div {...otherProps}>Hello {name}!</div> | |
); | |
export default SayHelloComponent; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PrivateComponent.jsx | |
// Author: Alok Ranjan Daftuar | |
// | |
import React from "react"; | |
import { withAuth } from "./withAuth.js"; | |
export class PrivateComponent extends React.Component { | |
render() { | |
return <div>Accessible only to authenticated users.</div>; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//withLoading.js | |
//Author: Alok Ranjan Daftuar | |
// | |
import React from 'react'; | |
function WithLoading(Component) { | |
return function WihLoadingComponent({ isLoading, ...props }) { | |
if (!isLoading) return <Component {...props} />; | |
return <p>Hold on, fetching data might take some time.</p>; | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//List.js | |
//Author: Alok Ranjan Daftuar | |
// | |
import React from "react"; | |
// | |
const List = (props) => { | |
const { repos } = props; | |
if (!repos) return null; | |
if (!repos.length) return <p>No repos, sorry</p>; | |
return ( |