I'm working on a small project that allows user to upload image and then the image will be displayed on a canvas.
I'm using react-konva for this.
I have a container component called DesignPage, which manages the state and pass event handlers to its children.
Inside this DesignPage component, I have 2 other components: Tools - Canvas
When I upload an image using Tools component, the image should be displayed on Canvas component.
I'm using react-dropzone inside Tools component to handle file upload
Inside this Canvas component, there is a child component called DesignImage, which is just for displaying the image.
But the thing is, it just doesn't change the image on canvas when I upload.
How can I fix that?
Here is my code:
DesignPage component:
import React, {Component} from 'react';
import {
Row,
Col
} from 'reactstrap';
import Tools from "../components/DesignPage/Tools";
import Canvas from "../components/DesignPage/Canvas";
import Styles from "../components/DesignPage/Styles";
class DesignPage extends Component {
state = {
text: '',
image: '',
files: []
};
static propTypes = {};
handleTextChange = e => {
this.setState({text: e.target.value});
};
handleFileDrop = files => {
this.setState({
files,
image: files[0].preview
});
};
render() {
return <Row>
<Col xs={12} md={4}>
<Tools
files={this.state.files}
onTextChange={this.handleTextChange}
onFileDrop={this.handleFileDrop}/>
</Col>
<Col xs={12} md={5}>
<Canvas
text={this.state.text}
image={this.state.image}/>
</Col>
<Col xs={12} md={3}>
<Styles/>
</Col>
</Row>;
}
}
export default DesignPage;
Tools component:
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {
TabContent,
TabPane,
Nav,
NavItem,
NavLink,
Row,
Col,
FormGroup,
Label
} from 'reactstrap';
import classnames from 'classnames';
import Dropzone from 'react-dropzone';
class Tools extends Component {
state = {
activeTab: '1'
};
toggle = (tab) => {
if (this.state.activeTab !== tab) {
this.setState({
activeTab: tab
});
}
};
render() {
return <Row>
<Col xs={12}>
<div>
<Nav tabs justified>
<NavItem>
<NavLink
className={classnames({active: this.state.activeTab === '1'})}
onClick={() => {
this.toggle('1');
}}
>
Text
</NavLink>
</NavItem>
<NavItem>
<NavLink
className={classnames({active: this.state.activeTab === '2'})}
onClick={() => {
this.toggle('2');
}}
>
Art
</NavLink>
</NavItem>
</Nav>
<TabContent activeTab={this.state.activeTab}>
<TabPane tabId="1">
<Row>
<Col sm="12">
<FormGroup>
<Label for={"custom-text"}>Enter text below</Label>
<textarea
className={"form-control"}
id={"custom-text"}
onChange={this.props.onTextChange}/>
</FormGroup>
<FormGroup>
<Label for={"font-select"}>Choose a font</Label>
</FormGroup>
</Col>
</Row>
</TabPane>
<TabPane tabId="2">
<Row>
<Col sm="12">
<FormGroup>
<div className="dropzone-container">
<Dropzone onDrop={this.props.onFileDrop}>
<p>Drop a design here, or click to select design to upload.</p>
</Dropzone>
</div>
</FormGroup>
</Col>
</Row>
</TabPane>
</TabContent>
</div>
</Col>
</Row>;
}
}
Tools.propTypes = {
files: PropTypes.array.isRequired,
onTextChange: PropTypes.func.isRequired,
onFileDrop: PropTypes.func.isRequired
};
export default Tools;
Canvas component:
import React from 'react';
import PropTypes from 'prop-types';
import {
Row,
Col
} from 'reactstrap';
import {Stage, Layer} from 'react-konva';
import UserText from "./Canvas/UserText";
import DesignImage from "./Canvas/DesignImage";
const Canvas = props => {
return <Row>
<Col xs={12} className={"canvas-container"}>
<div className={"object-container"}>
<img className={"object-img"} src={"images/iPhone5A.png"} alt={"iPhone5A"}/>
<div className="drawing-area">
<Stage width={window.innerWidth} height={window.innerHeight}>
<Layer>
<UserText text={props.text}/>
<DesignImage image={props.image}/>
</Layer>
</Stage>
</div>
</div>
</Col>
</Row>;
};
Canvas.propTypes = {
text: PropTypes.string.isRequired,
image: PropTypes.string.isRequired
};
export default Canvas;
DesignImage component:
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {Image} from 'react-konva';
class DesignImage extends Component {
state = {
image: null
};
static propTypes = {
image: PropTypes.string.isRequired
};
componentDidMount() {
const image = new window.Image();
image.src = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRYTULZCGUVEQJEXt9iB8PU4Kb2FMS9Z6ufR1FnQTdrEl5uBOl52Q';
image.onload = () => {
// setState will redraw layer
// because "image" property is changed
this.setState({
image: image
});
};
}
render() {
return <Image image={this.props.image} draggable={true}/>;
}
}
export default DesignImage;
You need write a code to update the image when the component has a new image from props.
class DesignImage extends Component {
state = {
image: null
};
static propTypes = {
image: PropTypes.string.isRequired
};
componentDidMount() {
this.updateImage();
}
componentDidUpdate() {
this.updateImage();
}
updateImage() {
const image = new window.Image();
image.src = this.props.image;
image.onload = () => {
this.setState({
image: image
});
};
}
render() {
return <Image image={this.state.image} draggable={true}/>;
}
}
Update:
You can use use-image hook for simpler image loading:
import useImage from 'use-image';
const DesignImage = ({ image }) => {
const imgElement = useImage(image);
return <Image image={imgElement} draggable={true}/>;
}
Related
What's up some guys... I'm having trouble displaying my data, which I fetch from my django modules. Fetching the data seems to work fine, however it won't render and display. Would very much appreciate any help. Right now only the containers and stuff is getting displayed, none of the data from the module. Here is my react component:
NewsItemPage.js
import "bootstrap/dist/css/bootstrap.min.css";
import React, {Component, useEffect, useState} from "react";
import {useParams} from "react-router-dom";
import {Card, Col, Container, Row} from "react-bootstrap";
import sheet from "./Images/metal-sheet.jpg";
import "./css/newsItem.css";
import {BoxArrowUpRight, Textarea} from "react-bootstrap-icons";
import {Link} from "react-router-dom";
function withParams(NewsItemPage){
return props => <NewsItemPage {...props} params={useParams()}/>
}
class NewsItemPage extends Component{
state={
item: {},
loading: true
}
async componentDidMount(){
let {id} = this.props.params;
try {
const res = await fetch(`http://localhost:8000/api/news/${id}`);
const item = await res.json();
this.setState({
item: item,
loading: false
})
}catch(e){
console.log(e);
}
}
render() {
if(this.state.loading){
return <h1 className="text-center">Vänligen vänta...</h1>
}
console.log(this.state.item);
return(
this.state.item ?
<Container fluid className="news-wrapper ">
<Row fluid className="news-page-col">
<Col className="news-page-col text-center mt-5 mb-5">
<h1>{this.state.item.title}</h1>
<hr className="divider"/>
</Col>
</Row>
<Row fluid className="gap-5 justify-content-center mt-5">
<Col>
<img src={this.state.item.image} alt="image"/>
</Col>
</Row>
<h4>{this.state.item.date}</h4>
<Row>
<Col>
<Textarea>{this.state.item.description}</Textarea>
</Col>
</Row>
</Container>
: <h1>Här finns inget ännu...</h1>
);
}
}
export default withParams(NewsItemPage);
And here is the output from the 'console.log(this.state.item);' inside the render method above:
0
:
created_on
:
"2023-01-18T16:01:15.744999Z"
description
:
"hello this is my testing news"
id
:
10
image
:
"http://localhost:8000/Images/Images/shutterstock_634808618-1-1024x683.png"
title
:
"testing"
[[Prototype]]
:
Object
length
:
1
[[Prototype]]
:
Array(0)
I use https://www.npmjs.com/package/react-bootstrap-dialog#dialogprompt-generators for my notification generating module. but only display buttons and no any text message shown in dialogbox..
enter image description here
onClick () {
this.dialog.show({
title: 'Greedings',
body: 'How are you?',
actions: [
Dialog.CancelAction(),
Dialog.OKAction()
],
bsSize: 'small',
onHide: (dialog) => {
dialog.hide()
console.log('closed by clicking background.')
}
})
}
This is the code part i used for that..Help me..
I have used material dashboard react free template for my project development, So in this dialog box doesn't work, but when i use codesandbox, it works properly, doesn't it work with material dashboard? .I can't understand why,If you know, Help me..
codesandbox.io/s/amazing-glade-lh5tl
import React from "react";
import firebase from "../../config/firebase.js";
import PropTypes from "prop-types";
import carfix from "./s.jpg";
// react plugin for creating charts
import {Link, withRouter} from 'react-router-dom';
import ChartistGraph from "react-chartist"; // #material-ui/core
import withStyles from "#material-ui/core/styles/withStyles";
import Icon from "#material-ui/core/Icon"; // #material-ui/icons
import Store from "#material-ui/icons/Store";
import Warning from "#material-ui/icons/Warning";
import DateRange from "#material-ui/icons/DateRange";
import LocalOffer from "#material-ui/icons/LocalOffer";
import Update from "#material-ui/icons/Update";
import ArrowUpward from "#material-ui/icons/ArrowUpward";
import AccessTime from "#material-ui/icons/AccessTime";
import Accessibility from "#material-ui/icons/Accessibility";
import BugReport from "#material-ui/icons/BugReport";
import Code from "#material-ui/icons/Code";
import Cloud from "#material-ui/icons/Cloud"; // core components
import GridItem from "components/Grid/GridItem.jsx";
import GridContainer from "components/Grid/GridContainer.jsx";
import Table from "components/Table/Table.jsx";
import Tasks from "components/Tasks/Tasks.jsx";
import CustomTabs from "components/CustomTabs/CustomTabs.jsx";
import Danger from "components/Typography/Danger.jsx";
import Card from "components/Card/Card.jsx";
import CardHeader from "components/Card/CardHeader.jsx";
import CardIcon from "components/Card/CardIcon.jsx";
import CardBody from "components/Card/CardBody.jsx";
import CardFooter from "components/Card/CardFooter.jsx";
import WorkAssign from "pages/work_assignmt.js";
import WorkDone from "pages/work_done.js";
import Modal from 'react-bootstrap/Modal';
import {Button} from 'react-bootstrap'
import Dialog from 'react-bootstrap-dialog'
import { bugs, website, server } from "variables/general.jsx";
import { dailySalesChart, emailsSubscriptionChart, completedTasksChart } from "variables/charts.jsx";
import dashboardStyle from "assets/jss/material-dashboard-react/views/dashboardStyle.jsx";
class Dashboard extends React.Component { constructor(props) {
super(props);
this.onClick = this.onClick.bind(this)
this.state = {
field1:0,
field2:0,
field3:0,
isDialogOpen: false
}; }
onClick () {
this.dialog.show({
title: 'Greedings',
body: 'How are you?',
actions: [
Dialog.CancelAction(),
Dialog.OKAction()
],
bsSize: 'small',
onHide: (dialog) => {
dialog.hide()
console.log('closed by clicking background.')
}
}) }
componentWillMount = async() =>{
this.setFieldData(); };
handleChange = (event, value) => {
this.setState({ value }); };
handleChangeIndex = index => {
this.setState({ value: index }); };
setFieldData = async() => {
var ref = firebase.database().ref("Daily Work Data").child("02-10-2019").child("Field 1");
var sum=0;
var ref = firebase.database().ref("Daily Work Data").child("02-10-2019").child("Field 2");
sum=0;
this.setState({field2: sum});
var ref = firebase.database().ref("Daily Work Data").child("02-10-2019").child("Field 3");
sum=0;
await ref.once('value',function (snapshot) {
snapshot.forEach(element => {
sum = sum + element.val().amount;
});
});
this.setState({field3: sum});
};
render() { const { classes } = this.props;
return (
<div
className="App"
style={{
backgroundImage: `linear-gradient(0deg,rgba(20,100,20,0.5), rgba(9, 93, 225, 0.0)),url(${carfix})`
}}>
<div className="wrappe">
<div>
<Dialog ref={(component) => { this.dialog = component }} />
</div>
<div>
<GridContainer>
<GridItem xs={12} sm={6} md={4}>
<Card>
<Button variant="underlined"
onClick={this.onClick}>
<CardHeader color="warning" stats icon>
<CardIcon color="warning">
<i class="material-icons">notifications_active</i>
</CardIcon>
<p className={classes.cardCategory}></p>
<h4 className={classes.cardTitle}>New Notifications</h4>
</CardHeader>
<CardFooter stats>
<div className={classes.stats}>
<hr/>
</div>
</CardFooter>
</Button>
</Card>
</GridItem>
<GridItem xs={12} sm={6} md={4}>
<Card>
<Button variant="underlined"
onClick={this.onClick}>
<CardHeader color="primary" stats icon>
<CardIcon color="primary">
<i class="material-icons">pan_tool</i>
</CardIcon>
<p className={classes.cardCategory}></p>
<h4 className={classes.cardTitle}>Pending Notifications</h4>
</CardHeader>
<CardFooter stats>
<div className={classes.stats}>
<hr/>
</div>
</CardFooter>
</Button>
</Card>
</GridItem>
<GridItem xs={12} sm={6} md={4}>
<Card>
<Button variant="underlined"
onClick={this.onClick}>
<CardHeader color="danger" stats icon>
<CardIcon color="danger">
<i class="material-icons">thumb_up</i>
</CardIcon>
<p className={classes.cardCategory}></p>
<h4 className={classes.cardTitle}>Responded Notifications</h4>
</CardHeader>
<CardFooter stats>
<div className={classes.stats}>
<hr/>
</div>
</CardFooter>
</Button>
</Card>
</GridItem>
</GridContainer>
<div>
</div>
</div> </div> </div>
); } }
Dashboard.propTypes = { classes: PropTypes.object.isRequired };
export default withStyles(dashboardStyle)(Dashboard);
I have a child functional component 'Display'. Which contains two buttons. The buttons toggle a state between true or false.
I want to pass this boolean value back to the parent container (component).
I then want to pass this boolean value to another child functional component called 'DisplayTitle'. Based on the boolean value I want to just update a string prop that gets rendered in the functional component.
I am slightly new to this. Should I be using redux or is there a more simple way of doing this? Thanks
Haven't yet
'Display' child component:
import * as React from 'react';
import Button from 'react-bootstrap/Button';
import Col from 'react-bootstrap/col';
interface Props {
buttonOneLabel: string;
buttonTwoLabel: string;
}
const Display = ({
buttonOneLabel,
buttonTwoLabel,
}: Props) => {
const [state, setVariant] = React.useState({ status: true });
return (
<>
<Col md="auto">
<Button
onClick={() => setVariant({ status: true })}
variant={state.status ? 'primary' : 'outline-primary'}
>
{buttonOneLabel}
</Button>
<Button
onClick={() => setVariant({ status: false })}
variant={state.status ? 'outline-primary' : 'primary'}
>
{buttonTwoLabel}
</Button>
</Col>
</>
);
};
export default Display;
'DisplayTitles' child component:
import * as React from 'react';
import Col from 'react-bootstrap/col';
interface Props {
title: string;
}
const DisplayTitles = ({
title,
}: Props) => (
<>
<Col>
<h3>{title}</h3>
</Col>
</>
);
export default DisplayTitles;
Parent component
import * as React from 'react';
import Jumbotron from 'react-bootstrap/Jumbotron';
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/row';
import Title from './Title';
import SearchBy from './SearchBy';
import QuickSearch from './QuickSearch';
import Dates from './Dates';
import Display from './Display';
import DisplayTitle from './DisplayTitle';
import RunReport from './RunReport';
import AdvancedSearch from './AdvancedSearch';
import Options from './Options';
const Header = () => (
<div className="daily-sales-header">
<Jumbotron>
<Container fluid>
<Title
title="Daily Sales"
subTitle="(Single Page)"
/>
<Row>
<SearchBy
colClass="search-by-col"
buttonId="search-by-button"
buttonLabel="Search by"
/>
<QuickSearch
buttonLabel="Quick Search"
eleClass="quick-search"
eleIdBtn="quick-search-button"
/>
<Dates
fromClass="from-date"
fromLabel="From"
toClass="to-date"
toLabel="To"
/>
<Display
buttonOneLabel="Department"
buttonTwoLabel="Sub-Department"
onSelectLanguage={handleVari}
/>
<RunReport
buttonLabel="Run Report"
/>
</Row>
<Row>
<AdvancedSearch
buttonClass="adv-search-btn pull-right"
buttonLabel="Advanced Search"
/>
</Row>
</Container>
</Jumbotron>
<Row>
<DisplayTitle
title="Department Sales"
/>
<Options />
</Row>
</div>
);
export default Header;
Lifting state up is the most simple approach here.
Parent component will hold state for all children components and pass
1. Values as props
2. Callbacks so children may change values
Example (not tested, use as hint only)
const Header = () => {
const [state, setVariant] = React.useState({ status: true });
return <div className="daily-sales-header">
/* ... */
<Display
uttonOneLabel="Department"
buttonTwoLabel="Sub-Department"
onSelectLanguage={handleVari}
setVariant={setVariant.bind(this)}
status={state.status}
/>
/* ... */
<DisplayTitle
title="Department Sales"
status={state.status}
/>
<Options />
</Row>
</div>
}
Disply component will be
import * as React from 'react';
import Button from 'react-bootstrap/Button';
import Col from 'react-bootstrap/col';
interface Props {
buttonOneLabel: string;
buttonTwoLabel: string;
status: boolean;
setVariant: (status: {status: boolean}) => void;
}
const Display = ({
buttonOneLabel,
buttonTwoLabel,
status,
setVariant
}: Props) => {
return (
<>
<Col md="auto">
<Button
onClick={setVariant.bind(this, { status: true })}
variant={status ? 'primary' : 'outline-primary'}
>
{buttonOneLabel}
</Button>
<Button
onClick={setVariant.bind(this, { status: false })}
variant={status ? 'outline-primary' : 'primary'}
>
{buttonTwoLabel}
</Button>
</Col>
</>
);
};
export default Display;
Display titles will be
// ...
interface Props {
title: string;
status: boolean;
}
const DisplayTitles = ({
title,
status
}: Props) => (
<>
<Col>
<h3>{title}</h3>
<h3>{status}</h3>
</Col>
</>
);
// ...
As a result, when you click button in Display component, setVariant from parent component will be called. It updates status in parent which will be immedeately propagated as props to both Display and DisplayTitles
By pressing a button and toggle showModal to true I am sending props to modal component AddEventModal. Inside AddEventModal component's constructor I assign a new state to open. After that I should be all set. But for some reason my open state in AddEventModal stays false.
Here is code:
import React, { Component } from 'react';
import Header from '../components/Header';
import Hour from '../components/Hour';
import Tile from '../components/Tile';
import CalEvent from '../components/CalEvent';
import AddButton from '../components/AddButton';
import AddEventModal from './AddEventModal';
import '../styles/calendar-grid.css';
class CalendarGrid extends Component {
constructor(){
super();
this.state = {
showModal: false
}
this.addEvent = this.addEvent.bind(this);
this.handleOpenModal = this.handleOpenModal.bind(this);
}
handleOpenModal() {
this.setState({ showModal: true });
}
handleCloseModal() {
this.setState({ showModal: false });
}
render(){
console.log(this.state.showModal);
const gridTiles = [];
return(
<div className="calendar-grid">
<AddButton showModal={this.handleOpenModal} />
<AddEventModal addEvent={this.addEvent} showModal={this.state.showModal}/>
</div>
)
}
}
export default CalendarGrid;
I am getting all props inside AddEventModal but it won't me to change open state.
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '#material-ui/core/styles';
import Typography from '#material-ui/core/Typography';
import Modal from '#material-ui/core/Modal';
import Button from '#material-ui/core/Button';
import Icon from '#material-ui/core/Icon';
import Close from '#material-ui/icons/Close';
import TextField from '#material-ui/core/TextField';
import DateRange from '#material-ui/icons/DateRange';
import Select from '#material-ui/core/Select';
import FormControl from '#material-ui/core/FormControl';
import MenuItem from '#material-ui/core/MenuItem';
import InputLabel from '#material-ui/core/InputLabel';
const styles = theme => ({
});
class AddEventModal extends React.Component {
constructor(props){
super(props);
this.state = {
open: this.props.showModal,
name: '',
date: new Date(),
time: ''
};
}
handleClose = () => {
this.setState({ open: false });
};
handleChange = name => event => {
this.setState({
[name]: event.target.value,
});
}
render() {
const { classes, showModal } = this.props;
console.log(`AddEventModal: ${this.props.showModal}`);
console.log(`AddEventModal: ${this.state.open}`);
return (
<div>
<Modal
aria-labelledby="simple-modal-title"
aria-describedby="simple-modal-description"
open={this.state.open}
onClose={this.handleClose}
>
<div style={getModalStyle()} className={classes.paper}>
<Close className={classes.closeIcon} onClick={this.handleClose} />
<Typography variant="h6" id="modal-title">
Create a New Event
</Typography>
<Typography variant="subtitle1" id="simple-modal-description">
<form className={classes.container} noValidate autoComplete="off">
<TextField
id="standard-name"
label="Event"
className={classes.textField}
value={this.state.name}
onChange={this.handleChange('name')}
margin="normal"
/>
<div className={classes.dateAndTime}>
<TextField
id="date"
label="Date"
type="date"
defaultValue={this.state.date}
className={classes.textFieldDate}
InputLabelProps={{
shrink: true,
}}
/>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="time-simple">Time</InputLabel>
<Select
value={this.state.time}
onChange={this.handleChange('time')}
inputProps={{
name: 'time',
id: 'time-simple',
}}
>
{this.timeRange()}
</Select>
</FormControl>
</div>
<Button variant="outlined" className={classes.saveButton} onClick={this.handleClose}>Save</Button>
</form>
</Typography>
</div>
</Modal>
</div>
);
}
}
AddEventModal.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(AddEventModal);
Any advise will be appreciated.
You're setting the open state but it's being overwritten by the showModal state coming in from props.
You should pass a handler, e.g. toggleModal into the modal, and use that to change the open prop, not the state inside the modal.
Here's an example.
import React from "react";
import ReactDOM from "react-dom";
const Modal = ({ open, toggle }) => {
if (open) {
return (
<React.Fragment>
<h1>Modal</h1>
<button onClick={toggle}>Close</button>
</React.Fragment>
);
}
return null;
};
class App extends React.Component {
state = {
open: false
};
toggle = () => {
this.setState({ open: !this.state.open });
};
render() {
return (
<React.Fragment>
<button onClick={this.toggle}>Open</button>
<Modal open={this.state.open} toggle={this.toggle} />
</React.Fragment>
);
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
CodeSandbox here.
Is there any way to setState({collapse: true}) for mobile screens only? How can i toggle the this.state.collapse based on current window size?
import React, { Component } from 'react';
import { Route, Redirect } from 'react-router-dom';
import $ from 'jquery';
import { Container, Row, Col, Collapse, Navbar, NavbarToggler, NavbarBrand, Nav, NavItem, NavLink } from 'reactstrap';
import { css } from 'glamor';
import { ToastContainer } from 'react-toastify';
import toast from '../toast';
import { BarLoader } from 'react-spinners';
// ---------------- Custom components
import DashboardNavbar from '../DashboardPage/Dashboard/DashboardNavbar/DashboardNavbar';
import Footer from '../Footer/Footer';
import './VideoPage.css';
class VideoPage extends Component {
constructor(props) {
super(props);
this.state = {
loading: false,
collapsed: false
};
this.toggleLoader = this.toggleLoader.bind(this);
this.notifySuccess = this.notifySuccess.bind(this);
this.notifyError = this.notifyError.bind(this);
this.toggleNavbar = this.toggleNavbar.bind(this);
}
notifySuccess(msg) {
toast.success(msg);
}
notifyError(msg) {
toast.error(msg);
}
toggleLoader() {
this.setState({
loading: !this.state.loading
});
}
// isAuthenticated() {
// const token = localStorage.getItem('authToken');
// if (token) {
// return true;
// }
// }
toggleNavbar() {
this.setState({
collapsed: !this.state.collapsed
});
}
render() {
const currentLocationPath = this.props.location.pathname;
const videoPage = currentLocationPath.includes('/video');
return (
<div className="VideoPage d-flex flex-column flex-grow">
<div className="VideoPageMain d-flex flex-grow">
<Container fluid>
<Row>
<DashboardNavbar videoPage={videoPage} />
</Row>
<Row>
<Col xs="12" sm="3">
<div className="sidebarMenu">
<Navbar dark>
<NavbarBrand className="mr-auto">Menu</NavbarBrand>
<NavbarToggler onClick={this.toggleNavbar} className="mr-2 d-sm-none" />
<Collapse isOpen={!this.state.collapsed} navbar>
<Nav navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink>
</NavItem>
<NavItem>
<NavLink href="https://github.com/reactstrap/reactstrap">Github</NavLink>
</NavItem>
</Nav>
</Collapse>
</Navbar>
</div>
</Col>
<Col xs="12" sm="9">.col</Col>
</Row>
</Container>
</div>
<Footer />
</div>
)
}
}
export default VideoPage;
basically i want the list to be hidden on mobile as there is button to toggle it which is hidden from tablet size and onwards.
It looks like there's a library for that: https://github.com/contra/react-responsive
Otherwise, you could add a listener to the resize event of window and fire that listener in the constructor to check the size.
You have 2 options:
1st option
Toggle classNames and let your CSS handles showing/hiding on different viewports
2nd option
use window.innerWidth in your isCollapsed
<Collapse isOpen={!this.state.collapsed && window.innerWidth < 768} navbar>
768 is just as an example