how to import images via props in react and use the 'import' path
By : Vesselin Tonchev
Date : March 29 2020, 07:55 AM
This might help you i'm passing the following as props. , An easy fix for what you're asking about code :
<img src={require(this.props.name)} alt=''/>
<img src={require('../assets/imgs/people/ahmed.png')} alt=''/>
<img src={require(`../assets/imgs/people/${this.props.name.toLowerCase()}.png`)}/>
|
React Cannot access props value outside class using (props)=>
By : Chad Henderson
Date : March 29 2020, 07:55 AM
it should still fix some issue You have to pass down the props from the GoogleMaps component. You could explicitly pass down the lat and lng props, or you can use the spread syntax to pass down all props. code :
class GoogleMaps extends Component {
render() {
return (
<div>
<GoogleMapGazi
containerElement={<div style={{ height: `500px`, width: "600px" }} />}
mapElement={<div style={{ height: `100%` }} />}
{...this.props}
/>
</div>
);
}
}
|
How to pass import as props parameters in React JS
By : user3454374
Date : March 29 2020, 07:55 AM
it helps some times As already mentioned by @Dellirium you should be passing different values over props to your components. Here is how it works: code :
const animationDatas = [
{ id: 'first' },
{ id: 'second' },
{ id: 'third' },
];
class LottiesC extends React.Component {
render() {
const defaultOptions = {
// loop: true,
// autoplay: true,
animationData: this.props.animationData,
// rendererSettings: {
// preserveAspectRatio: "xMidYMid slice",
// },
}
return (
<div className="x">
{/** <Lottie options={defaultOptions} height={600} width={600} /> **/}
{JSON.stringify(defaultOptions)}
</div>
)
}
}
const App = () => {
return (
<section className="index">
<div><LottiesC animationData={animationDatas[0]} /></div>
<div><LottiesC animationData={animationDatas[1]} /></div>
<div><LottiesC animationData={animationDatas[2]} /></div>
</section>
)
}
ReactDOM.render(<App />, document.querySelector('#app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="app"></div>
|
Import image using this.props.src in React
By : go vegan
Date : March 29 2020, 07:55 AM
this will help If you're using webpack, I'm going to assume that you're using the webpack image loader. If that's the case it means that you're importing your images in your component, probably using named imports. In that case you can pass the named import as a prop to either a child component or use it directly on the component where the import lives.
|
Using React props vs import , What is the best choice?
By : Gal Barna
Date : March 29 2020, 07:55 AM
With these it helps is a standalone component and passing it down to you child components in that manner completely unnecessary. If you want to pass components from parent to child, use the special prop children instead. code :
return (<Component><FormattedMessage /></Component>)
return (<div>{props.children}</div>)
|