ReactJS Component that retrieves quotes

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












I have created the following React Component and wanted to have feedback about if its SOLID or not, and what can I do to make it SOLID?
I do believe its SOLID but would like feedback from guys with more experience.



The code renders a list of Quotes from a Sharepoint List, it has a mock provider for mock data and a SP provider to get real data.



My structure:



enter image description here



And my code as follows:



Solid.tsx



import * as React from 'react';
import styles from './Solid.module.scss';
import ISolidProps from './ISolidProps';
import escape from '@microsoft/sp-lodash-subset';
import IQuotes, IQuote from './QuoteContracts';
import IDataReader, DataReaderFactory from './DataReader';
import ISolidState from './ISolidState';


export default class Solid extends React.Component<ISolidProps, ISolidState>

constructor()
super();
this._dataReader = DataReaderFactory.getReader(this.context);


private _dataReader : IDataReader;

public render(): React.ReactElement<ISolidProps>
return (
<div className= styles.solid >
<div className= styles.container >
<div className= styles.row >
<div className= styles.column >
<span className= styles.title >Welcome to SharePoint!</span>
<p className= styles.subTitle >Customize SharePoint experiences using Web Parts.</p>
<p className= styles.description >escape(this.props.description)</p>
<a href="https://aka.ms/spfx" className= styles.button >
<span className= styles.label >Learn more</span>
</a>
this.renderQuotes()
</div>
</div>
</div>
</div>

);


fetchData = () =>
this._dataReader.getData().then((response) =>
this.setState(
quotes: response.Quotes,
);
);


componentDidMount()
this.fetchData();


renderQuotes = () => this.state.quotes.map(quote => (
<div>$escape(quote.Quote)</div>
<div class="$styles.author">$escape(quote.Author)</div>
);




Datareader.ts



import 
Version,
Environment,
EnvironmentType
from '@microsoft/sp-core-library';
import IWebPartContext from '@microsoft/sp-webpart-base';

import IQuotes from './QuoteContracts';
import SPDataReader from './SPDataReader';
import MockDataReader from './MockDataReader';

export interface IDataReader
getData(): Promise<IQuotes>;


export class DataReaderFactory
public static getReader(context: IWebPartContext)
if (Environment.type === EnvironmentType.SharePoint



ISolidProps.ts



export interface ISolidProps 
description: string;



ISolidState.ts



import IQuote, IQuotes from "./QuoteContracts";

export interface ISolidState
quotes: IQuote;



Mockdata.ts



import IQuote from './QuoteContracts';

export default class MockData

private static _items: IQuote = [
Author: 'Author 1', Quote: 'Quote 1' ,
Author: 'Author 2', Quote: 'Quote 2' ,
Author: 'Author 3', Quote: 'Quote 3' ];

public static get(): Promise<IQuote>
return new Promise<IQuote>((resolve) =>
resolve(MockData._items);
);




MockDatareader.ts



import SPDataReader from './SPDataReader';
import IQuotes, IQuote from './QuoteContracts';

export class MockDataReader extends SPDataReader
constructor()
super(null, null);


getData(): Promise<IQuotes>
return this.get().then((data: IQuote) =>
var listData: IQuotes = Quotes: data ;
return listData;
) as Promise<IQuotes>;


private static _items: IQuote = [
Author: 'Author 1', Quote: 'Quote 1' ,
Author: 'Author 2', Quote: 'Quote 2' ,
Author: 'Author 3', Quote: 'Quote 3' ];

private get(): Promise<IQuote>
return new Promise<IQuote>((resolve) =>
resolve(MockDataReader._items);
);




QuoteContracts.ts



export interface IQuotes 
Quotes: IQuote;


export interface IQuote
Author: string;
Quote: string;







share|improve this question

















  • 4




    This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. Questions should include a description of what the code does.
    – Phrancis
    May 22 at 20:03






  • 2




    Going along with the comment by Phrancis: What task does this code accomplish? Please tell us, and also make that the title of the question via edit. Maybe you missed the placeholder on the title element: "State the task that your code accomplishes. Make your title distinctive.". Also from How to Ask: "State what your code does in your title, not your main concerns about it.".
    – Sam Onela
    May 22 at 20:20










  • you say, "what can I do to fix it", is something broken? The code needs to function as intended in order to be on-topic. if I were to reopen because context was added it may be closed because of being broken. please give more insight about your code and what it does.
    – Malachi♦
    May 23 at 14:02










  • ohh I am sorry for the typo, insteaf What can I do to fix it, I meant What can I do to make it SOLID. Is that clear?
    – Luis Valencia
    May 23 at 14:06










  • I will reopen this, but keep in mind that you will likely get more questions about the code and what it does. the more information that you give us the better.
    – Malachi♦
    May 23 at 14:10
















up vote
0
down vote

favorite












I have created the following React Component and wanted to have feedback about if its SOLID or not, and what can I do to make it SOLID?
I do believe its SOLID but would like feedback from guys with more experience.



The code renders a list of Quotes from a Sharepoint List, it has a mock provider for mock data and a SP provider to get real data.



My structure:



enter image description here



And my code as follows:



Solid.tsx



import * as React from 'react';
import styles from './Solid.module.scss';
import ISolidProps from './ISolidProps';
import escape from '@microsoft/sp-lodash-subset';
import IQuotes, IQuote from './QuoteContracts';
import IDataReader, DataReaderFactory from './DataReader';
import ISolidState from './ISolidState';


export default class Solid extends React.Component<ISolidProps, ISolidState>

constructor()
super();
this._dataReader = DataReaderFactory.getReader(this.context);


private _dataReader : IDataReader;

public render(): React.ReactElement<ISolidProps>
return (
<div className= styles.solid >
<div className= styles.container >
<div className= styles.row >
<div className= styles.column >
<span className= styles.title >Welcome to SharePoint!</span>
<p className= styles.subTitle >Customize SharePoint experiences using Web Parts.</p>
<p className= styles.description >escape(this.props.description)</p>
<a href="https://aka.ms/spfx" className= styles.button >
<span className= styles.label >Learn more</span>
</a>
this.renderQuotes()
</div>
</div>
</div>
</div>

);


fetchData = () =>
this._dataReader.getData().then((response) =>
this.setState(
quotes: response.Quotes,
);
);


componentDidMount()
this.fetchData();


renderQuotes = () => this.state.quotes.map(quote => (
<div>$escape(quote.Quote)</div>
<div class="$styles.author">$escape(quote.Author)</div>
);




Datareader.ts



import 
Version,
Environment,
EnvironmentType
from '@microsoft/sp-core-library';
import IWebPartContext from '@microsoft/sp-webpart-base';

import IQuotes from './QuoteContracts';
import SPDataReader from './SPDataReader';
import MockDataReader from './MockDataReader';

export interface IDataReader
getData(): Promise<IQuotes>;


export class DataReaderFactory
public static getReader(context: IWebPartContext)
if (Environment.type === EnvironmentType.SharePoint



ISolidProps.ts



export interface ISolidProps 
description: string;



ISolidState.ts



import IQuote, IQuotes from "./QuoteContracts";

export interface ISolidState
quotes: IQuote;



Mockdata.ts



import IQuote from './QuoteContracts';

export default class MockData

private static _items: IQuote = [
Author: 'Author 1', Quote: 'Quote 1' ,
Author: 'Author 2', Quote: 'Quote 2' ,
Author: 'Author 3', Quote: 'Quote 3' ];

public static get(): Promise<IQuote>
return new Promise<IQuote>((resolve) =>
resolve(MockData._items);
);




MockDatareader.ts



import SPDataReader from './SPDataReader';
import IQuotes, IQuote from './QuoteContracts';

export class MockDataReader extends SPDataReader
constructor()
super(null, null);


getData(): Promise<IQuotes>
return this.get().then((data: IQuote) =>
var listData: IQuotes = Quotes: data ;
return listData;
) as Promise<IQuotes>;


private static _items: IQuote = [
Author: 'Author 1', Quote: 'Quote 1' ,
Author: 'Author 2', Quote: 'Quote 2' ,
Author: 'Author 3', Quote: 'Quote 3' ];

private get(): Promise<IQuote>
return new Promise<IQuote>((resolve) =>
resolve(MockDataReader._items);
);




QuoteContracts.ts



export interface IQuotes 
Quotes: IQuote;


export interface IQuote
Author: string;
Quote: string;







share|improve this question

















  • 4




    This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. Questions should include a description of what the code does.
    – Phrancis
    May 22 at 20:03






  • 2




    Going along with the comment by Phrancis: What task does this code accomplish? Please tell us, and also make that the title of the question via edit. Maybe you missed the placeholder on the title element: "State the task that your code accomplishes. Make your title distinctive.". Also from How to Ask: "State what your code does in your title, not your main concerns about it.".
    – Sam Onela
    May 22 at 20:20










  • you say, "what can I do to fix it", is something broken? The code needs to function as intended in order to be on-topic. if I were to reopen because context was added it may be closed because of being broken. please give more insight about your code and what it does.
    – Malachi♦
    May 23 at 14:02










  • ohh I am sorry for the typo, insteaf What can I do to fix it, I meant What can I do to make it SOLID. Is that clear?
    – Luis Valencia
    May 23 at 14:06










  • I will reopen this, but keep in mind that you will likely get more questions about the code and what it does. the more information that you give us the better.
    – Malachi♦
    May 23 at 14:10












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have created the following React Component and wanted to have feedback about if its SOLID or not, and what can I do to make it SOLID?
I do believe its SOLID but would like feedback from guys with more experience.



The code renders a list of Quotes from a Sharepoint List, it has a mock provider for mock data and a SP provider to get real data.



My structure:



enter image description here



And my code as follows:



Solid.tsx



import * as React from 'react';
import styles from './Solid.module.scss';
import ISolidProps from './ISolidProps';
import escape from '@microsoft/sp-lodash-subset';
import IQuotes, IQuote from './QuoteContracts';
import IDataReader, DataReaderFactory from './DataReader';
import ISolidState from './ISolidState';


export default class Solid extends React.Component<ISolidProps, ISolidState>

constructor()
super();
this._dataReader = DataReaderFactory.getReader(this.context);


private _dataReader : IDataReader;

public render(): React.ReactElement<ISolidProps>
return (
<div className= styles.solid >
<div className= styles.container >
<div className= styles.row >
<div className= styles.column >
<span className= styles.title >Welcome to SharePoint!</span>
<p className= styles.subTitle >Customize SharePoint experiences using Web Parts.</p>
<p className= styles.description >escape(this.props.description)</p>
<a href="https://aka.ms/spfx" className= styles.button >
<span className= styles.label >Learn more</span>
</a>
this.renderQuotes()
</div>
</div>
</div>
</div>

);


fetchData = () =>
this._dataReader.getData().then((response) =>
this.setState(
quotes: response.Quotes,
);
);


componentDidMount()
this.fetchData();


renderQuotes = () => this.state.quotes.map(quote => (
<div>$escape(quote.Quote)</div>
<div class="$styles.author">$escape(quote.Author)</div>
);




Datareader.ts



import 
Version,
Environment,
EnvironmentType
from '@microsoft/sp-core-library';
import IWebPartContext from '@microsoft/sp-webpart-base';

import IQuotes from './QuoteContracts';
import SPDataReader from './SPDataReader';
import MockDataReader from './MockDataReader';

export interface IDataReader
getData(): Promise<IQuotes>;


export class DataReaderFactory
public static getReader(context: IWebPartContext)
if (Environment.type === EnvironmentType.SharePoint



ISolidProps.ts



export interface ISolidProps 
description: string;



ISolidState.ts



import IQuote, IQuotes from "./QuoteContracts";

export interface ISolidState
quotes: IQuote;



Mockdata.ts



import IQuote from './QuoteContracts';

export default class MockData

private static _items: IQuote = [
Author: 'Author 1', Quote: 'Quote 1' ,
Author: 'Author 2', Quote: 'Quote 2' ,
Author: 'Author 3', Quote: 'Quote 3' ];

public static get(): Promise<IQuote>
return new Promise<IQuote>((resolve) =>
resolve(MockData._items);
);




MockDatareader.ts



import SPDataReader from './SPDataReader';
import IQuotes, IQuote from './QuoteContracts';

export class MockDataReader extends SPDataReader
constructor()
super(null, null);


getData(): Promise<IQuotes>
return this.get().then((data: IQuote) =>
var listData: IQuotes = Quotes: data ;
return listData;
) as Promise<IQuotes>;


private static _items: IQuote = [
Author: 'Author 1', Quote: 'Quote 1' ,
Author: 'Author 2', Quote: 'Quote 2' ,
Author: 'Author 3', Quote: 'Quote 3' ];

private get(): Promise<IQuote>
return new Promise<IQuote>((resolve) =>
resolve(MockDataReader._items);
);




QuoteContracts.ts



export interface IQuotes 
Quotes: IQuote;


export interface IQuote
Author: string;
Quote: string;







share|improve this question













I have created the following React Component and wanted to have feedback about if its SOLID or not, and what can I do to make it SOLID?
I do believe its SOLID but would like feedback from guys with more experience.



The code renders a list of Quotes from a Sharepoint List, it has a mock provider for mock data and a SP provider to get real data.



My structure:



enter image description here



And my code as follows:



Solid.tsx



import * as React from 'react';
import styles from './Solid.module.scss';
import ISolidProps from './ISolidProps';
import escape from '@microsoft/sp-lodash-subset';
import IQuotes, IQuote from './QuoteContracts';
import IDataReader, DataReaderFactory from './DataReader';
import ISolidState from './ISolidState';


export default class Solid extends React.Component<ISolidProps, ISolidState>

constructor()
super();
this._dataReader = DataReaderFactory.getReader(this.context);


private _dataReader : IDataReader;

public render(): React.ReactElement<ISolidProps>
return (
<div className= styles.solid >
<div className= styles.container >
<div className= styles.row >
<div className= styles.column >
<span className= styles.title >Welcome to SharePoint!</span>
<p className= styles.subTitle >Customize SharePoint experiences using Web Parts.</p>
<p className= styles.description >escape(this.props.description)</p>
<a href="https://aka.ms/spfx" className= styles.button >
<span className= styles.label >Learn more</span>
</a>
this.renderQuotes()
</div>
</div>
</div>
</div>

);


fetchData = () =>
this._dataReader.getData().then((response) =>
this.setState(
quotes: response.Quotes,
);
);


componentDidMount()
this.fetchData();


renderQuotes = () => this.state.quotes.map(quote => (
<div>$escape(quote.Quote)</div>
<div class="$styles.author">$escape(quote.Author)</div>
);




Datareader.ts



import 
Version,
Environment,
EnvironmentType
from '@microsoft/sp-core-library';
import IWebPartContext from '@microsoft/sp-webpart-base';

import IQuotes from './QuoteContracts';
import SPDataReader from './SPDataReader';
import MockDataReader from './MockDataReader';

export interface IDataReader
getData(): Promise<IQuotes>;


export class DataReaderFactory
public static getReader(context: IWebPartContext)
if (Environment.type === EnvironmentType.SharePoint



ISolidProps.ts



export interface ISolidProps 
description: string;



ISolidState.ts



import IQuote, IQuotes from "./QuoteContracts";

export interface ISolidState
quotes: IQuote;



Mockdata.ts



import IQuote from './QuoteContracts';

export default class MockData

private static _items: IQuote = [
Author: 'Author 1', Quote: 'Quote 1' ,
Author: 'Author 2', Quote: 'Quote 2' ,
Author: 'Author 3', Quote: 'Quote 3' ];

public static get(): Promise<IQuote>
return new Promise<IQuote>((resolve) =>
resolve(MockData._items);
);




MockDatareader.ts



import SPDataReader from './SPDataReader';
import IQuotes, IQuote from './QuoteContracts';

export class MockDataReader extends SPDataReader
constructor()
super(null, null);


getData(): Promise<IQuotes>
return this.get().then((data: IQuote) =>
var listData: IQuotes = Quotes: data ;
return listData;
) as Promise<IQuotes>;


private static _items: IQuote = [
Author: 'Author 1', Quote: 'Quote 1' ,
Author: 'Author 2', Quote: 'Quote 2' ,
Author: 'Author 3', Quote: 'Quote 3' ];

private get(): Promise<IQuote>
return new Promise<IQuote>((resolve) =>
resolve(MockDataReader._items);
);




QuoteContracts.ts



export interface IQuotes 
Quotes: IQuote;


export interface IQuote
Author: string;
Quote: string;









share|improve this question












share|improve this question




share|improve this question








edited May 23 at 21:36









200_success

123k14143399




123k14143399









asked May 22 at 19:41









Luis Valencia

105112




105112







  • 4




    This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. Questions should include a description of what the code does.
    – Phrancis
    May 22 at 20:03






  • 2




    Going along with the comment by Phrancis: What task does this code accomplish? Please tell us, and also make that the title of the question via edit. Maybe you missed the placeholder on the title element: "State the task that your code accomplishes. Make your title distinctive.". Also from How to Ask: "State what your code does in your title, not your main concerns about it.".
    – Sam Onela
    May 22 at 20:20










  • you say, "what can I do to fix it", is something broken? The code needs to function as intended in order to be on-topic. if I were to reopen because context was added it may be closed because of being broken. please give more insight about your code and what it does.
    – Malachi♦
    May 23 at 14:02










  • ohh I am sorry for the typo, insteaf What can I do to fix it, I meant What can I do to make it SOLID. Is that clear?
    – Luis Valencia
    May 23 at 14:06










  • I will reopen this, but keep in mind that you will likely get more questions about the code and what it does. the more information that you give us the better.
    – Malachi♦
    May 23 at 14:10












  • 4




    This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. Questions should include a description of what the code does.
    – Phrancis
    May 22 at 20:03






  • 2




    Going along with the comment by Phrancis: What task does this code accomplish? Please tell us, and also make that the title of the question via edit. Maybe you missed the placeholder on the title element: "State the task that your code accomplishes. Make your title distinctive.". Also from How to Ask: "State what your code does in your title, not your main concerns about it.".
    – Sam Onela
    May 22 at 20:20










  • you say, "what can I do to fix it", is something broken? The code needs to function as intended in order to be on-topic. if I were to reopen because context was added it may be closed because of being broken. please give more insight about your code and what it does.
    – Malachi♦
    May 23 at 14:02










  • ohh I am sorry for the typo, insteaf What can I do to fix it, I meant What can I do to make it SOLID. Is that clear?
    – Luis Valencia
    May 23 at 14:06










  • I will reopen this, but keep in mind that you will likely get more questions about the code and what it does. the more information that you give us the better.
    – Malachi♦
    May 23 at 14:10







4




4




This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. Questions should include a description of what the code does.
– Phrancis
May 22 at 20:03




This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. Questions should include a description of what the code does.
– Phrancis
May 22 at 20:03




2




2




Going along with the comment by Phrancis: What task does this code accomplish? Please tell us, and also make that the title of the question via edit. Maybe you missed the placeholder on the title element: "State the task that your code accomplishes. Make your title distinctive.". Also from How to Ask: "State what your code does in your title, not your main concerns about it.".
– Sam Onela
May 22 at 20:20




Going along with the comment by Phrancis: What task does this code accomplish? Please tell us, and also make that the title of the question via edit. Maybe you missed the placeholder on the title element: "State the task that your code accomplishes. Make your title distinctive.". Also from How to Ask: "State what your code does in your title, not your main concerns about it.".
– Sam Onela
May 22 at 20:20












you say, "what can I do to fix it", is something broken? The code needs to function as intended in order to be on-topic. if I were to reopen because context was added it may be closed because of being broken. please give more insight about your code and what it does.
– Malachi♦
May 23 at 14:02




you say, "what can I do to fix it", is something broken? The code needs to function as intended in order to be on-topic. if I were to reopen because context was added it may be closed because of being broken. please give more insight about your code and what it does.
– Malachi♦
May 23 at 14:02












ohh I am sorry for the typo, insteaf What can I do to fix it, I meant What can I do to make it SOLID. Is that clear?
– Luis Valencia
May 23 at 14:06




ohh I am sorry for the typo, insteaf What can I do to fix it, I meant What can I do to make it SOLID. Is that clear?
– Luis Valencia
May 23 at 14:06












I will reopen this, but keep in mind that you will likely get more questions about the code and what it does. the more information that you give us the better.
– Malachi♦
May 23 at 14:10




I will reopen this, but keep in mind that you will likely get more questions about the code and what it does. the more information that you give us the better.
– Malachi♦
May 23 at 14:10















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194970%2freactjs-component-that-retrieves-quotes%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194970%2freactjs-component-that-retrieves-quotes%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation