Swipe through components with big data sets (React) - reactjs

I'm building a React app that takes in a lot of data from temperature sensors at several different places and displays the data with chart.js.
I have made one component that fetch data from one place and that component is called from App.js, so now I could copy this component / or fetch data from another place if I implement it that way.
Next step is to find a way to swipe through these components. I don't know what to use or how I would go about to solve this, so I'm looking for ideas on how to solve this.
I have tried using react-swipeable-views. Code is provided in this post. This seems to be a simple solution, but I'm not sure if it's a good idea to do like this. I guess it would be quite heavy with large data sets? If I understand the way React works it would pull in data from all components to a browser and then hide it until it's showed?
I have also looked at this article: https://coursework.vschool.io/react-transitions-with-react-transition-group/
Here react-transition-group is used, but I'm not sure on how to implement the swipe part here since that is not discussed in the article.
Any ideas on how to solve this?
import React, {Component} from 'react';
import Test from './Test';
import SwipeableViews from 'react-swipeable-views';
const styles = {
slide: {
padding: 15,
minHeight: 800,
color: '#fff',
},
slide1: {
background: '#FEA900',
},
slide2: {
background: '#B3DC4A',
},
slide3: {
background: '#6AC0FF',
},
};
class App extends React.Component{
constructor(){
super();
this.state={
foo: 'bar'
}
}
}
render(){
return(
<div className="App">
<SwipeableViews enableMouseEvents>
<div style={Object.assign({}, styles.slide, styles.slide1)}>
slide n°1
<Test /> // <-- This would be a component with large data sets
</div>
<div style={Object.assign({}, styles.slide, styles.slide2)}>
slide n°2
</div>
<div style={Object.assign({}, styles.slide, styles.slide3)}>
slide n°3
</div>
</SwipeableViews>
</div>
)
}
export default App;

I have not used it before but looking at the docs, using react-swipeable-views should be fine, since it "quickly renders the first slide, then lazy-loads the others." (from https://github.com/oliviertassinari/react-swipeable-views). Furthermore you can customize how many slides before and after the currently displayed one are being rendered (see https://react-swipeable-views.com/api/api/#virtualize).
Also, it might be a good idea, to catch up on some react concepts (https://reactjs.org/docs/introducing-jsx.html). React does not "hide" any components, it only renders the ones you choose to the DOM and updates what is necessary to get the DOM to reflect your state. So for example, if you have multiple pages (p1, p2, p3), each rendering one component (c1, c2, c3), while being on page p1, only the component c1 would be rendered to the DOM.

Related

react-native-webview performance issues when rendering html string

Am trying to run some html tags am getting from an api but finding it difficult to make the performance as good as native
I have tried using react-native-webview but having serious performance issues with it.
I have also tried react-native-render-html but also had some issues with running some tags like , and inline styles same with react-native-htmlview. It renders every other tag correctly with native performance
This is an example of an html string am getting from an api (toRender)
import React, {Component} from 'react'
import HTML from 'react-native-render-html';
const toRender = "<p style='text-decoration: underline'>divide <sup>10<sup>/<sub>2</sub></p>"
class QuestionScreen extends Component{
render{
return(
<View style={{ flex: 1 }}>
<HTML
html={toRender}
/>
</View>
)
}
}
export default QuestionScreen

How do I modify a page title based on react component using .NET Core react with redux project?

I thought this would be simple, and the answer probably is and I'm just missing something, but I'm having trouble with updating a header/layout component based on what page I'm on.
Code wise, I have just installed the ASP.NET Core 2.0 template that uses React with Redux. I'm familiar with React, but TypeScript and Redux is new to me so it's hopefully a syntax/layout issue I'm having, as I can do this in a standalone React project. If you create a new project in Visual Studio following this template, you'll see the code that I'm trying to modify (New > Project > ASP.NET Core Web Application > React.js and Redux).
The TypeScript Layout file (ClientApp/components/Layout.tsx) is where I want to put essentially:
<h1>{ this.state.title }</h1>
...and further on from this use a Header tag to load a Header component that holds the title.
I want to then change the title based on whether I am on the Home, FetchData, or Counter page, which I imagine is just a basic string set on each component file.
If you can't open the project file for whatever reason, here is the layout I'm working with:
Layout component (should set the title here)
import * as React from 'react';
import { NavMenu } from './NavMenu';
export interface HeaderState {
title: string;
}
export class Layout extends React.Component<{}, {}> {
public render() {
return <div className='container-fluid'>
// !!!!---> Create a <Header /> component that includes the page title, set on a page by page basis
<div className='row'>
<div className='col-sm-3'>
<NavMenu />
</div>
<div className='col-sm-9'>
{ this.props.children }
</div>
</div>
</div>;
}
}
I would potentially include more component code for those who can't use the Visual Studio project, but it's pretty bloated with a lot of code that doesn't apply here. I just thought someone could help without needing it, but happy to provide if necessary!
Any help or pointers in the right direction are greatly appreciated! Apologies if this question and answer is somewhere. I have Googled and searched SO but no luck.

Re-routing a Component without Reloading Entire Page

I have a React+Django app which is a custom video player, and I'm currently working on a related videos / queue at the end of the video. I have it working, if I use a simple window.location.replace with the link to the next video. However, it would be a lot smoother to only reload the video player.
From the many many threads I've read on SO, it seems that this it is possible to re-route my "main" component within a child component in React, but none of the methods have worked for me and I have a slightly different case than everything I've read. If the video playing depends on my URL (or Route), is it even still possible to reload without re-rendering the entire page?
Here's a barebones version of the relevant code:
Index.js:
class Welcome extends React.Component {
render() {
return (
<BrowserRouter>
<App/>
</BrowserRouter>
)
}
}
const element = <Welcome/>;
ReactDOM.render(
element,
document.getElementById('container')
);
App.js:
class App extends React.Component {
render() {
return (
<Row id="app-container" className="h-100 justify-content-center align-items-center">
<Switch>
<Route path='/app/:number' component={Player}/>
</Switch>
</Row>
)
}
}
export default App
Queue.js, Note: this is obviously just the part I'm having trouble with. I have clickable imgs to do the window.location.replace method.
<div>
<Link to='app/1' replace>
Previous Video
</Link>
<div>
The Link actually does change the URL in the way I want, but doesn't reload the App. I've spent a long time trying to implement solutions to this problem from other SO posts, but I'm worried that once I get it, it will end up forcing the whole page to reload anyway. Can anyone tell me if it's possible to JUST re-reroute my app? It's alright if the URL doesn't change, as long as the app is based on the new route.
Thanks in advance

React Transition Group And Animations

The problem is I have a form whit three states: default, error and success. Depending on the state, a specific component is rendered into the dom.
I need to add a fade in out animation when this component enters or leave.
I've tried whith custom CSS, GSAP ( but don't want to install more packages to my project ) and now trying with react-transition-group.
To keep is simple I've created the "error" component as follow:
export default class NewsletterFormError extends React.Component {
componentWillMount() {
}
componentDidMount() {
}
render() {
return (
<div className="NewsletterFormError">
I'm an error message
<style jsx>{`
.NewsletterFormError {
font-size: 50px;
}
`}</style>
</div>
)
}
}
And on the index page I have:
{ this.state.formError &&
<CSSTransitionGroup
transitionName="test"
transitionAppear={true}
transitionAppearTimeout={200}
transitionEnter={true}
transitionEnterTimeout={2000}
transitionLeave={true}
transitionLeaveTimeout={2000}>
<NewsletterFormError />
</CSSTransitionGroup>
}
For some reson, when this.state.formError is true, the component renders and the fade in is done, but when the state chages to false, the fade out is not working.
Unfortunately, pure React CSS Transition groups can't trigger an animation when a component is unmounted. See this github issue for more details. This repo with a comparison of animation methods in react may be helpful, they recommend using React CSS Transition groups in conjunction with GSAP or Anime.js

How to add custom style to meteor accounts ui for react?

I have just started learning react and Meteor. I am using the okgrow:accounts-ui-react to show a login and signup form on my site. You only have to add the component to show the signup/login form on your page. However, the dropdown form is ugly and does not go well with my site's design. Therefore, I want to learn how can you modify the styles of such meteor components. In this case, how can you change the style of this component to appear as a materially design form. I am using materialize.css and I want to know how can I give this login component a materialize design inspired look? I want to make the dropdown inspired by material design and also change the contents of the form. The following is my component that I created by following a video on leveluptuts.
import React, {Component} from 'react';
import { LoginButtons } from 'meteor/okgrow:accounts-ui-react';
class App extends Component{
render(){
return (
<div>
<header>
<h1>Level Up Voting </h1>
<LoginButtons/>
</header>
</div>
);
}
}
The following image shows how my login button appears on screen:

Resources