How to make props button link clickable? - react-router

I have a React card component as in the code below:
import React from "react";
class Cardlist extends React.Component {
render() {
return(
<div className="cardlist">
<div className="cardlist-body">
<h2>{this.props.title}</h2><br/>
<p>{this.props.text}</p><br/><br/>
<button className="button-49">{this.props.btnlink}</button>
</div>
</div>
)
}
}
export default Cardlist;
import React from "react";
import Cardlist from "./Cardlist";
const Services = () => {
return(<section id="services">
<div class="servicesContainer">
<div class="servicesContent">
<Cardlist title="Pain Management" text="We offer patients the very best pain medications and treatments. We advise our patients to seek treatment for their chronic pain and learn that management is possible with the right tools [...]" btnlink ="Read More"/>
</div>
<div class="servicesContent">
<Cardlist title="Dermatology" text="The compounding pharmacist prepares therapies customized for the individual patient for a very wide range of dermatological conditions. Such skin conditions can spell not only physical di [...]" btnlink ="Read More"/>
</div>
<div class="servicesContent">
<Cardlist title="Pediatric" text="Children and medications often times just do not mix. Children often resist taking a medication because they don’t like the taste. Swallowing pills is often difficult for younger children [...]" btnlink ="Read More"/>
</div>
<div class="servicesContent">
<Cardlist title="Hormone Replacement Therapy" text="Children and medications often times just do not mix. Children often resist taking a medication because they don’t like the taste. Swallowing pills is often difficult for younger children [...]" btnlink ="Read More" />
</div>
</div>
</section>);
}
export default Services;
Clearly, as you can see I can't pass a link to btnlink ="Read More". When is the best and easiest way to assign every button its own LINK (external or internal link)?
You can see the design on live website: http://fusionrxny.com

you need a onClick listener on your button element
import React from "react";
class Cardlist extends React.Component {
handleClick = () => {
// this will open your link in new tab
window.open(this.props.linkUrl, '_blank');
}
render() {
return(
<div className="cardlist">
<div className="cardlist-body">
<h2>{this.props.title}</h2><br/>
<p>{this.props.text}</p><br/><br/>
<button className="button-49" onClick={this.handleClick}>{this.props.btnlink}</button>
</div>
</div>
)
}
}
export default Cardlist;
or you can replace your button element with a link element
import React from "react";
class Cardlist extends React.Component {
render() {
return(
<div className="cardlist">
<div className="cardlist-body">
<h2>{this.props.title}</h2><br/>
<p>{this.props.text}</p><br/><br/>
<a className="button-49" href={this.props.linkUrl}>{this.props.btnlink}</button>
</div>
</div>
)
}
}
export default Cardlist;
you would provide different urls like this
import React from "react";
import Cardlist from "./Cardlist";
const Services = () => {
return(<section id="services">
<div class="servicesContainer">
<div class="servicesContent">
<Cardlist
title="Pain Management"
text="We offer patients the very best pain medications and treatments. We advise our patients to seek treatment for their chronic pain and learn that management is possible with the right tools [...]"
btnlink ="Read More"
linkUrl='your url to more info on Pain Managment'
/>
</div>
<div class="servicesContent">
<Cardlist
title="Dermatology"
text="The compounding pharmacist prepares therapies customized for the individual patient for a very wide range of dermatological conditions. Such skin conditions can spell not only physical di [...]"
btnlink ="Read More"
linkUrl='your url to more info on Dermatology'
/>
</div>
<div class="servicesContent">
<Cardlist
title="Pediatric"
text="Children and medications often times just do not mix. Children often resist taking a medication because they don’t like the taste. Swallowing pills is often difficult for younger children [...]"
btnlink ="Read More"
linkUrl='your url to more info on Pediatric'
/>
</div>
<div class="servicesContent">
<Cardlist
title="Hormone Replacement Therapy"
text="Children and medications often times just do not mix. Children often resist taking a medication because they don’t like the taste. Swallowing pills is often difficult for younger children [...]"
btnlink ="Read More"
linkUrl='your url to more info on Hormone Replacment Terapy'
/>
</div>
</div>
</section>);
}
export default Services;

Related

Ionic React too slow to render JSON file containing 100+ objects in IonCard component

I am creating a mobile app with Ionic React. I render multiple IonCards with dynamic data coming from a local JSON file. Actually, I'm mapping through the JSON file. Everything is fine. But it takes a couple of seconds to render all the cards. I want to minimize the loading time. Please help me with how do I optimize the render time and overall performance of the application. The code is below:
//imports...
import data from "../db/data.json";
const Products: React.FC = (filterText) => {
const [searchText, setSearchText] = useState("");
const categories = vocabTopics
//filtering CATEGORIES
.filter((topic) => {return topic.title.toLowerCase().indexOf(searchText.toLowerCase()) >= 0;})
.map((topic) => {
return (
<IonCol size="12" key={topic.id}>
<IonCard mode="md" routerLink={topic.route} className="except-home-screen-card no-margin no-radius-card">
<div className="flex">
<div className="card-img">
<img src={topic.thumbnail}></img>
</div>
<div className="flex-justify-space-b-w">
<div>
<IonCardSubtitle className="except-home-screen-card-subtitle">{topic.subtitle}</IonCardSubtitle>
<IonCardTitle className="except-home-screen-card-title">{topic.title}</IonCardTitle>
</div>
<div>
<IonIcon icon={chevronForwardOutline} className="card-right-icon"/>
</div>
</div>
</div>
</IonCard>
</IonCol>
);
});
return (
<IonPage>
<IonHeader className="ion-no-border">
<IonToolbar className="top-header">
<IonButtons slot="start" className="top-header-icons color-primary">
<IonBackButton defaultHref="home" /></IonButtons>
<div className="top-title-container">
<IonTitle className="ion-text-center v-center">Products</IonTitle>
</div>
</IonToolbar>
</IonHeader>
<IonContent fullscreen className="bg-style">
<div className="center padding-y">
<h1 className="lg-text ion-no-margin equal-padding">Products Categories</h>
<p className="ion-text-center ion-no-margin subtitle">70+ CATEGORIES</p>
</div>
<IonGrid className="my-grid ion-no-padding">
<IonSearchbar spellcheck={true} autocorrect="on" className="searchbar" value={searchText} mode="ios" onIonChange={(e) => setSearchText(e.detail.value!)}></IonSearchbar>
<IonRow className="center-padding">
<div className="card-container fluid">
{categories}
</div>
</IonRow>
</IonGrid>
</IonContent>
</IonPage>
);
};
export default Products;
I suppose 100 Cards are not visible at the same time in a single "view", so the only solution is the "infinite scrolling" and Display/Create them only when them should became visible. (example: https://forum.ionicframework.com/t/infinite-scrolling-of-data-from-the-api/172933)

Says {profilePic} un-defined

VS says I have no issues but all my browsers say it is un-defined.. All input is appreciated.
import React from 'react';
import "./Post.css";
import{Avatar} from '#material-ui/core';
function Post({ pofilePic, image, username, timestamp,message}) {
return (
<div className="post">
<div className="post__top">
<Avatar src={profilePic}
className="post__avatar"/>
<div className="post__topInfo">
<h3>{username}</h3>
<p>Timesatmp....</p>
</div>
</div>
```
It’s spelled pofilePic in one place and profilePic in another.

Can I get all the text between every <p> and </p> in a certain ID

I used the code below but it only gets me the text between one, when it should get me the text between 5 <p> and </p>
> var myHTMLString = try String(contentsOf: myURL, encoding: .ascii)
while let idRange = myHTMLString.range(of: "post-51"){
myHTMLString=myHTMLString.substring(from: idRange.upperBound)
if let paraRange = myHTMLString.range(of: "<p>"){
myHTMLString=myHTMLString.substring(from: paraRange.upperBound)
if let paraCloseRange = myHTMLString.range(of: "</p>"){
HTMLData = myHTMLString.substring(to: paraCloseRange.lowerBound)
textViewer.text = HTMLData
myHTMLString = myHTMLString.substring(from: paraCloseRange.upperBound)
}else{
//Handle paragraph close tag not found
print("Handle paragraph close tag not found")
}
}else{
//Handle paragraph start tag not found
print("Handle paragraph start tag not found")
}
}
The full HTML string is:`
<!-- main content -->
<div id="content" class="main-content-inner col-sm-12 col-md-9">
<header>
<h1 class="page-title">Community</h1>
</header>
<article id="post-51" class="post-51 page type-page status-publish hentry">
<!-- .entry-header -->
<div class="entry-content">
<h1>Your Experience, Your Programs</h1>
<p>The Purdue Honors College is dedicated to providing meaningful opportunities to enhance the honors student experience. We are building an interdisciplinary community of scholars by adding value through specialized programming and events that are connected to our pillars. The Honors College strives to create an environment in which every student can feel connected, learn, and grow as they each pursue greatness. To reach your full potential in the Honors College, students should attend at least three honors programs per semester outside of the regular curriculum requirements. We invite you to be a part of one of our many upcoming events as we ignite the imagination of our community and forge the future of our college.</p>
<hr />
<h3>Events Calendar</h3>
<p>The Honors College hosts events to keep students engaged with their peers and the Honors College faculty.</p>
<p>Click here to learn more about upcoming events in the Honors College.</p>
<hr />
<h3>Honors College and Residences</h3>
<p>The new 324,000-square-foot Honors College and Residences is the first of its kind in the state of Indiana. It encourages scholarship and connects students with faculty while being emblematic of the Mission of the Purdue Honors College: from the locally sourced building materials to LEED certification and interactive learning spaces.</p>
<p>Click here to learn more about the new Honors College and Residences buildings.</p>
<hr />
<h3>Honors Network News</h3>
<p>Click here to view the Honors Network News archive.</p>
<hr />
<h3>News</h3>
<p>Stay up to date with news about the Honors College. Learn about the awesome things our students are doing and follow the Honors College on social media.</p>
<p>Click here to view more news about the Honors College.</p>
<hr />
<h3>Photo Gallery</h3>
<p>Click here to view photos of Honors College events.</p>
<hr />
<h3>Published Works</h3>
<p>Click here to view the published works of the Honors College.</p>
<hr />
<h3>Signature Programs</h3>
<p>Click here to learn more about Signature Programs from the Honors College.</p>
<hr />
</div><!-- .entry-content -->
</article><!-- #post-## -->
`
Change you code to this to loop though all after you find the id. Take a look at my comment that it's very import to break the while loop after certain condition is met.
var myHTMLString = try String(contentsOf: myURL, encoding: .ascii)
if let idRange = myHTMLString.range(of: "post-51"){
myHTMLString=myHTMLString.substring(from: idRange.upperBound)
while let paraRange = myHTMLString.range(of: "<p>"){
myHTMLString=myHTMLString.substring(from: paraRange.upperBound)
if let paraCloseRange = myHTMLString.range(of: "</p>"){
HTMLData = myHTMLString.substring(to: paraCloseRange.lowerBound)
textViewer.text = HTMLData
//AFTER YOU GET THE NEEDED INFORMATION, DO A break HERE to get out of while loop or you will loop through all <p>
myHTMLString = myHTMLString.substring(from: paraCloseRange.upperBound)
}else{
//Handle paragraph close tag not found
print("Handle paragraph close tag not found")
}
}
}else{
print("Handle id not found")
}
I think that using an off-screen web view to temporarily load the HTML and retrieve the contents you're after is not out of the question. Here's an example of how to do that:
class ViewController: UIViewController {
// Declared as a property of the class to ensure it is not freed
// from memory (because we're not adding it to the view hierarchy).
let webView = UIWebView()
override func viewDidLoad() {
super.viewDidLoad()
webView.delegate = self
webView.loadHTMLString("<html><head></head><body><div id=\"hello\"><p>First</p><p>Second</p><p>Third</p></div></body></html>", baseURL: nil)
}
}
extension ViewController: UIWebViewDelegate {
func webViewDidFinishLoad(_ webView: UIWebView) {
let result = webView.stringByEvaluatingJavaScript(from: "Array.prototype.slice.call(document.getElementById('hello').getElementsByTagName('p')).map(function(p) { return p.innerHTML }).join('|')")
print(result)
}
}
Note that stringByEvaluatingJavaScript can't handle array responses, so we concatenate the contents of the p tags with a pipe | character to return it to Swift. You can then split the string on the pipes to get an array back. You can change the delimiter to anything that you're sure will never be present naturally inside the p tags.
Also, Array.prototype.slice.call is just to convert the HTMLCollection that getElementsByTagName returns into an array.

Unknown prop warning react js `iconClassNameRight`

Hi there I want to know why it is throwing a warning on the console
Warning: Unknown prop `iconCLassNameRight` on <div> tag. Remove this prop from the element. For details, see link fb me
in div (created by Paper)
in Paper (created by AppBar)
in AppBar (created by App)
in div (created by App)
in MuiThemeProvider (created by App)
in App
The is the code I am working on it is on meteorjs and material ui
import React, { Component } from 'react';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import RaisedButton from 'material-ui/RaisedButton';
import AppBar from 'material-ui/AppBar';
import Player from './Player.jsx';
import TeamList from './Team-list.jsx';
import TeamStats from './Team-stats.jsx';
export default class App extends Component {
render(){
return (
<MuiThemeProvider>
<div className="container">
<AppBar
title="Soccer Application" iconCLassNameRight="muidocs-icon-navigation-expand-more" showMenuIconButton={false} />
<div className="row">
<div className="col s12 m7"> <Player /> </div>
<div className="col s12 m5"> <TeamStats /> </div>
<div className="col s12 m5"> <TeamList /> </div>
</div>
</div>
</MuiThemeProvider>
)
}
}
I want to know why this is throwing an error. The line of interest is in the appbar component iconClassNameRight property. Any help would be greatly appreaciated. Thank you.
Props in React are case-sensitive.
Try replacing iconCLassNameRight (uppercase L) to iconClassNameRight (lowercase L)

how can I iterate through this json file?

I want to do my cv in react.
I have a json file that contains all my experience, education and more however I come across a problem when I output the data
{
"experience":[
{
"Title":"Somewhere",
"Date":"2015 - 2015",
"Description":
[
"Participate in the full development lifecycle, following a SCRUM methodology applied to core product",
"Participate in the full development lifecycle, following a SCRUM methodology applied to core product",
"Participate in the full development lifecycle, following a SCRUM methodology applied to core product"
]
},
{
"Title":"Somewhere",
"Date":"2015 - 2015",
"Description":
[
"Participate in the full development lifecycle, following a SCRUM methodology applied to core product",
"Participate in the full development lifecycle, following a SCRUM methodology applied to core product",
"Participate in the full development lifecycle, following a SCRUM methodology applied to core product"
]
}
]
}
I am calling it in experience.js
const Experience = (props) => (
<div className="container">
<p className="subtitle">WORK EXPERIENCE</p>
<hr className="subtitles"/>
<ul className="left-box">
{props.data.map((info,i) =>
<li key={i} className="top">
<div className="year">
<h4>{info.Date}</h4>
<span> {info.Title}</span>
</div>
<div className="box-content" >
<h4 className="sameHeightTitle">Front End Developer</h4>
<ul className="left-box-content">
<li className="sec-layer">
{info.Description}
</li>
</ul>
</div>
</li>
)}
</ul>
</div>
);
the problem is instead of having the description in bullet form I have it all on the same bullet. Basically every string that starts with Participate in my json file should be next to a new bullet.The following is screenshot of the output:
EDIT: Answer
const Experience = (props) => (
<div className="container">
<p className="subtitle">WORK EXPERIENCE</p>
<hr className="subtitles"/>
<ul className="left-box">
{props.data.map((info,i) =>
<li key={i} className="top">
<div className="year">
<span className="sub-sub-title"> {info.Title}</span>
<h4>{info.Date}</h4>
</div>
<div className="box-content" >
<h4 className="sameHeightTitle">Front End Developer</h4>
<ul className="left-box-content">
{info.Description.map((newDesc, o)=>
<li>
{newDesc}
</li>
)}
</ul>
</div>
</li>
)}
</ul>
</div>
);
Your Description is an array. You need to iterate over it. What js library are you using? You'll need to find out how you iterate over a list in that language.
This isn't the syntax for the foreach loop, but you'll get the idea.
foreach(var description in info.Description){
<li className="sec-layer">
{description}
</li>
}