reactjs

This site can’t be reached docker-compose

ε祈祈猫儿з 提交于 2021-02-11 01:59:04
问题 I am trying to use docker-compose for react-typescript application with webpack-dev-server below is my Dockerfile FROM node:lts-slim RUN mkdir -p /usr/src/app WORKDIR /usr/src/app EXPOSE 3000 CMD [ "npm", "start" ] "start": "webpack-dev-server --port 3000" this package.json line docker-compose.yml version: "3" services: frontend: container_name: awesome_web build: context: ./client dockerfile: Dockerfile image: webpack ports: - "3000:3000" volumes: - ./client:/usr/src/app I executed command

Updating state - why creating a new copy of state when calling setState?

六月ゝ 毕业季﹏ 提交于 2021-02-11 01:12:16
问题 React docs: Never mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable. That's clear. class App extends React.Component { state = { data: [] } the following I understand updateState(event) { const {name, value} = event.target; let user = this.state.user; // this is a reference, not a copy... user[name] = value; // return this.setState({user}); // so this could replace the previous mutation } this following I

“npx create-react-app appname” not working

可紊 提交于 2021-02-10 23:59:26
问题 When I run npx create-react-app appname I get the following error message: You are running `create-react-app` 4.0.0, which is behind the latest release (4.0.1). We no longer support global installation of Create React App. Please remove any global installs with one of the following commands: - npm uninstall -g create-react-app - yarn global remove create-react-app The latest instructions for creating a new app can be found here: https://create-react-app.dev/docs/getting-started/ npm ERR! code

Infinite console logging in React.js component

与世无争的帅哥 提交于 2021-02-10 23:30:27
问题 I'm working on my MERN app, and when I'm logging smth in NewsPage component, it logs infinitely. NewsPage component: const NewsPage = ({news, fetchNews}) => { const postNews = (title, body) => { axios.post("http://localhost:9000/news", { title, body }); } useEffect(() => { fetchNews(); }, [fetchNews, postNews]) return ( <> <AddNewsForm postNews={postNews}/> <h1>News:</h1> <NewsItemPage news={news} /> </> ); }; const mapStateToProps = state => ({ news: state.news }) export default connect

Set a certain interval for x-axis ticks in ApexCharts

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 23:28:27
问题 Introduction: I have a ApexCharts chart with data from an API. I'm using an API called finnhub to get the stock market data which is displayed on the chart. The data returned has an array of prices and a corresponding array of times, which are not at an equal interval (stock market is closed at certain times) (prices on the y-axis and time on the x-axis). The data I'm getting is quite high resolution, which means there are a LOT of labels on the x-axis, making it look really cluttered and

react-datepicker years range

匆匆过客 提交于 2021-02-10 22:43:37
问题 I am using the react-datepicker package.https://reactdatepicker.com/ I am trying to create a custom date picker with a years range, following their example but I can not make the range work. I am not even sure if I am importing that range from the right place tbh. My code: import DatePicker, {getYear, getMonth, range} from 'react-datepicker'; import "react-datepicker/dist/react-datepicker.css"; const Foo = () => { const [startDate, setStartDate] = useState(new Date()); const years = range

React - import multiple svgs in a single file

一世执手 提交于 2021-02-10 22:40:25
问题 I have multiple svg files and I want to import and export all of them in a single file: icons.js import IconVideoOn from '../../assets/img/icons/video-on.svg'; import IconVideoOff from '../../assets/img/icons/video-off.svg'; import IconMicOn from '../../assets/img/icons/mic-on.svg'; import IconMicOff from '../../assets/img/icons/mic-off.svg'; . . . export default { IconVideoOn, IconVideoOff, IconMicOn, IconMicOff }; then I'm importing them like this MyComponent.jsx import { IconVideoOn } from

Why does SetTimeout code still executes after clearTimeout

﹥>﹥吖頭↗ 提交于 2021-02-10 21:13:22
问题 I have following code in my react component: //some code var timeout = null; //global variable //some more code useEffect(() => { if(...some condition) { console.log('test1'); timeout = setTimeout(() => { console.log('test2'); }, 15 * 1000); } else { console.log('test3'); clearTimeout(timeout); } }, [some other condition]); The output I get in the console: test1 test3 test2 //after 15 seconds So I am trying to start timeout which will log 'test2', if in the meantime timeout was not cleared.

How to use use-supercluster with Typescript

此生再无相见时 提交于 2021-02-10 21:12:32
问题 I am having troubles while implementing use-supercluster with TypeScript. I am trying to use clusters to differentiate two types of data in a Google Map with something like red clusters vs. green clusters. I can't find any documentation related to use this library with TypeScript and I am not getting enough information from its types: So, what is argument P ? I was following the use-supercluster creator's guide to add clusters but after installing supercluster types I am getting errors here:

How to use use-supercluster with Typescript

被刻印的时光 ゝ 提交于 2021-02-10 21:12:20
问题 I am having troubles while implementing use-supercluster with TypeScript. I am trying to use clusters to differentiate two types of data in a Google Map with something like red clusters vs. green clusters. I can't find any documentation related to use this library with TypeScript and I am not getting enough information from its types: So, what is argument P ? I was following the use-supercluster creator's guide to add clusters but after installing supercluster types I am getting errors here: