React Component doesnt render within script statement
Date : March 29 2020, 07:55 AM
wish helps you I'm finding trouble rendering a child component in react. I'm using React-Toolbox for styling. , You aren't returning CardActions in your map function: render(){
const dummyText = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
return(
<Card className={styles.card} key={this.props.id}>
<CardTitle
title={this.state.project.project_name}
subtitle={this.state.project.category}
/>
<CardText>{dummyText}</CardText>
{this.state.project.skills.map((skill) => {
console.log('Skill is: ',skill);
return (
<CardActions key={skill.id}>
<Chip>{skill.skill_name}</Chip>
</CardActions>
);
})}
</Card>
);
}
|
React Router changes Link but doesnt render proper component
Tag : reactjs , By : Hugo Hernan Buitrago
Date : March 29 2020, 07:55 AM
I hope this helps you . The problem is you have multiple instances of browser router and history is getting confused. You can fix this by re-organising the structure of application like the below example. // *-----------------------*
// | MAIN-APP COMPONENT |
// *-----------------------*
import React, { Component } from "react";
import { Col, Well, Panel } from "react-bootstrap";
import { Route, Switch } from "react-router-dom";
import SideNavComponent from "./SideNavComponent";
const HomeComponent = () => <div>Home</div>;
const GraphComponent = () => <div>Graph</div>;
const DeviceComponent = () => <div>Device</div>;
const TransformationComponent = () => <div>Transformation</div>;
class App extends Component {
render() {
return (
<div>
<div className="header" />
<div className="body">
<Col md={3}>
<Well>
<SideNavComponent />
</Well>
</Col>
<Col md={9}>
<Panel>
<Switch>
<Route path="/device" component={DeviceComponent} />
<Route path="/transform" component={TransformationComponent} />
<Route path="/graph" component={GraphComponent} />
<Route exact path="/" component={HomeComponent} />
</Switch>
</Panel>
</Col>
</div>
<div className="footer" />
</div>
);
}
}
export default App;
// *-----------------------*
// | SIDENAV-COMPONENT |
// *-----------------------*
import React, { Component } from "react";
import { Nav, NavItem } from "react-bootstrap";
import { Link } from "react-router-dom";
class SideNavComponent extends Component {
render() {
return (
<div style={{ flexDirection: "column" }}>
<Link to="/">Home</Link>
<Link to="/graph">Graphs</Link>
</div>
);
}
}
export default SideNavComponent;
// *-----------------------*
// | MAIN.JS (ENTRY POINT) |
// *-----------------------*
import React from 'react'
import { render } from 'react-dom'
import App from './components/App';
import { BrowserRouter } from 'react-router-dom';
render((
<BrowserRouter>
<App />
</BrowserRouter>
), document.getElementById('root'));
|
How to get root component to re-render in react-native with redux (Open source project)
Date : March 29 2020, 07:55 AM
I hope this helps you . Since you're aleady using react-redux, therefore you can use the connect function of the same library. Since Connect requires a new instance of the component that you are using, therefore it can be done as shown below. import { Provider, connect } from 'react-redux';
class RootContainer extends Component {
render() {
const {locale} = this.props
return (
<ThemeProvider theme={colors}>
<FormattedWrapper locale={locale} messages={messages}>
<Root>
<StatusBar barStyle='light-content' backgroundColor='transparent' translucent />
{ Platform.OS === 'android' && Platform.Version >= 20 ? <StatusBarAndroid /> : null }
<Navigator />
</Root>
</FormattedWrapper>
</ThemeProvider>
);
}
}
const mapState = state = ({
locale: state.language.language
})
ConnectedRootContainer = connect(mapState, null)(RootContainer);
class App extends Component {
render() {
return (
<Provider store={store}>
<ConnectedRootContainer/>
</Provider>
);
}
}
export default App;
|
Shallow render doesnt render component wrapped in Consumer(jest/Enzyme)
Date : December 25 2020, 12:30 AM
I think the issue was by ths following , In Enzyme you should explicitly render renderProp: enzyme
|
Only render specific component in a big react project
Date : September 26 2020, 10:00 PM
I think the issue was by ths following , Try dynamic import: Before: import { add } from './math';
console.log(add(16, 26));
import("./math").then(math => {
console.log(math.add(16, 26));
});
|