score:1
Accepted answer
You need to add props to BoxOne component
import React from "react";
import styles from "./BoxOne.css";
function BoxOne({style={}, label=''}) {
return(
<div id="boxOneContainer" style={style}>
<p className="boxOneText">{label}</p>
</div>
);
}
export default BoxOne;
Then you can use it in the parent component like this:
import React from "react";
import "./Canvas.css";
import Workpanel from "../components/Workpanel";
import BoxOne from "../components/BoxOne";
class Canvas extends React.Component {
render () {
return(
<div>
<Workpanel />
<div className="canvasContainer">
<div className="topicPlanner">
<p>Topic Planner</p>
<div className="topicVl"></div>
</div>
<BoxOne text="Box One" />
<BoxOne text="Box One Rendered Again" style={{color: '#0F0', top: '178px', left: '605px'}} />
</div>
</div>
)
};
}
export default Canvas;
Altough at this point, you probably want to change the name of the component from BoxOne
to Box
...
Since you have five Boxes, it will be cleaner to use an array like this:
const boxes = [
{ label: 'box1', style: {} },
{ label: 'box2', style: {left: '100px'} },
{ label: 'box3', style: {left: '200px'} },
{ label: 'box4', style: {left: '300px'} },
{ label: 'box5', style: {left: '400px'} },
];
class Canvas extends React.Component {
render () {
return(
<div>
<Workpanel />
<div className="canvasContainer">
<div className="topicPlanner">
<p>Topic Planner</p>
<div className="topicVl"></div>
</div>
{boxes.map(box => (
<BoxOne label={box.label} style={box.style} key={box.label} />
)}
</div>
</div>
)
};
}
export default Canvas;
For more info about props, please read https://reactjs.org/docs/components-and-props.html
Source: stackoverflow.com
Related Query
- How to render a div component multiple times with different background color and text in React?
- React Router v6 : How to render multiple component inside and outside a div with the same path
- With React Router : How to render a component multiple times with differents props each time in a Route?
- How to render a React component multiple times but each time with an updated State?
- How to render multiple components with different component name?
- How to call Api multiple times with different parameters and then store the responses?
- React: How to render same component with same onClick and different drops
- How to render one component multiple times and show the result one after the other?
- React: How to render same page that includes multiple components and forms for 2 types of user with different permissions?
- Multiple times render in react functional component with hooks
- How to conditionally render a DIV and REACT component for OPENING and CLOSING tags?
- How to render only the concerned component with a custom hook and useContext
- How to change the text color and background color of ant-tooltip component
- Loop through array and render multiple instances of a child component with that data with React?
- Rendering a component multiple times with different props in React
- How to set the background color of material ui drawer component with styled-components?
- How to 1). put a div , 2). render a component without Route inside <Routes> with React Router in v6 React?
- MaterialUI: Why does setting background color on Select component hides the InputLabel text and how could I avoid it happening?
- React Convert Div and Table Component Into PDF With Multiple Pages and CSS
- How user string input will show as background color in a div in react JS functional component
- How do i render multiple props in a single component and then pass those props to a child component in React
- how to change the antd carousel dot shape and color with styled component
- Testing Library : How to render the same component multiple times without coupling
- Jest with React - How do you render an entire component and test it?
- How to render ReactJS with component name and its props?
- How to return multiple times same component but with independant state?
- How to set child div background color based on position in parent with a linear gradient
- How to render different component with react router after user logged in
- How to render single react component with different data?
- React: same component reappearing multiple times in the app, how can I make sure that all states are captured accurately and not just the last?
More Query from same tag
- map() function in Reactjs is not working with state
- How To Connect to two different web server in localhost
- how to make variables inside useEffect accessible from outside?
- Wrapping last two words in a string with NavLink dynamically
- Axios headers work for Django GET request, but not PUT request
- cannot change state in firebase auth signInWithEmailAndPassword
- Only the ID of data is being returned from an HTTP PUT request in Axios
- How to get the current full URL in Next.js/Typescript component?
- Integrate Phaser Game with React as component
- Why is day off by 1 and hours is way off on mor ISO 8601 in Moment js?
- React: apply multiple filters to array
- Failed prop type: Invalid props.style key 'textAlign' supplied to 'View'
- Navigation in Sidebar not working using Next.js
- Cant use CSS and justify content on react Bootstrap
- executing a node js child process after click html button
- Custom mailchimp signup form in React
- How to override non-generic types such as @types/History for useHitory()?
- Passing props to NavBar doesn't update component
- React upload file to mongodb node Js multer
- Is it possible to separate presentation and logic for component in Redux/React?
- ReactiveVar not re-rendering React component
- Can't resolve react-hot-loader/patch
- Unable to fetch data from local json file by axios
- Forwarding props from parent to child component
- Create an input that allows only numbers, decimals and commas
- Can't setup nginx proxy to docker container with react
- passing argument to function in react without using arrow function in onClick handler
- How to preview video on upload in the webpage
- Axios React - not setting state, what am I doing wrong?
- How to initialize a method in state in a constructor that is dependent on another methods value