import React from 'react';
import $ from "jquery";
import moment from "moment";
import DateRangePicker from "react-bootstrap-daterangepicker";
import dateRangePickerCss from '../../../../media/css/shared/daterangepicker.css'
const Filter = () => {
const openDropdown = (e) => {
var parent = e.target.parentElement;
$(parent).siblings().removeClass('open');
$(parent).toggleClass('open');
};
const handleEvent = (event, picker) => {
console.log(picker.startDate);
};
return (
<DateRangePicker onEvent={handleEvent}>
<a class="selected-txt">Filter by Date</a>
</DateRangePicker>
)
}
export default Filter
The datepicker: https://github.com/skratchdot/react-bootstrap-daterangepicker
When i am using the picker it gives me the following error on the console
Uncaught Error: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded
EDIT
This is my package.json
{
"name": "a",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev_build": "webpack --display-modules --progress --colors --watch",
"prod_build": "sh frt_build_script.sh"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"css-loader": "^0.28.0",
"eslint": "^3.15.0",
"eslint-config-standard": "^7.1.0",
"eslint-loader": "^1.6.3",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-react": "^6.10.0",
"eslint-plugin-standard": "^2.1.1",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^0.10.1",
"webpack": "^2.2.1"
},
"peerDependencies": {
"react": "^15.4.2"
},
"dependencies": {
"axios": "^0.12.0",
"jquery": "^3.2.1",
"react-dom": "^15.4.2",
"react-modal": "^1.7.3",
"react-redux": "^5.0.3",
"react-router": "^3.0.2",
"redux": "^3.6.0",
"redux-logger": "^2.8.2",
"redux-promise-middleware": "^4.2.0",
"redux-thunk": "^2.2.0"
}
}
I think your reason of using datepicker is because you want the user to only allow date to be chosen in between specified start date till end date. Am I right? If I am, then you can do it simply by giving input type date.. If it is the reason, let me know. Will update the answer with the solution. :)
Related
three version:^0.140.2
#react-three/fiber version:^8.0.19
#react-three/drei version:^9.11.0
node version:14.18.13
npm (or yarn) version: 1.22.17 (yarn)
react version:17.0.1
react-dom version:17.0.1
Problem description:
Implementing react three drei above my NextJS app getting an error when go to the page which import react three drei, like the following:
./node_modules/#react-three/drei/web/Html.js:3:0 Module not found: Can't resolve 'react-dom/client' Import trace for requested module: ./node_modules/#react-three/drei/index.js ./components/Model3D/ThreeDModel.js ./pages/new.js
Expected:
I go to 'new' page, then I can load 3d model with .glb format from HTML input tag using useGLTF
Relevant Code:
import React from 'react'
import { useGLTF } from '#react-three/drei/core/useGLTF'
import { OrbitControls } from '#react-three/drei'
import { parseImgUrl } from 'utils/common'
const Model1 = ({ threeDUrl }) => {
const loadedGltf = useGLTF(parseImgUrl(threeDUrl), true)
return (
<>
<primitive object={loadedGltf.scene} dispose={null} />
<OrbitControls />
<ambientLight />
</>
)
}
export { Model1 }
Suggested Solution:
At this time, I think root cause of the error is that my react three drei which I used don't supported react#17.0.1. I expected that previous react three drei version support react#17.0.1 then really wonder what specified version that support react#17.0.1 or maybe the error was caused by other things. Thank you for your support, that's always my pleasure.
This is the entire dependencies within package.json
{
"name": "paras-v2-landing",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"dev:testnet": "PORT=8081 dotenv -e .env.testnet next dev",
"dev:mainnet": "PORT=8082 dotenv -e .env.mainnet next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"format": "prettier --write .",
"prettier-check": "prettier --check .",
"prepare": "husky install"
},
"dependencies": {
"#draft-js-plugins/anchor": "^4.1.1",
"#draft-js-plugins/buttons": "^4.0.0",
"#draft-js-plugins/divider": "^4.1.1",
"#draft-js-plugins/editor": "^4.0.0",
"#draft-js-plugins/focus": "^4.1.0",
"#draft-js-plugins/image": "^4.0.0",
"#draft-js-plugins/inline-toolbar": "^4.1.0",
"#draft-js-plugins/linkify": "^4.1.0",
"#draft-js-plugins/static-toolbar": "^4.0.0",
"#draft-js-plugins/video": "^4.1.0",
"#react-three/drei": "^9.11.0",
"#react-three/fiber": "^8.0.19",
"#sentry/nextjs": "^6.12.0",
"#tailwindcss/line-clamp": "^0.3.1",
"axios": "^0.21.0",
"blurhash": "^1.1.3",
"cachios": "^3.0.0",
"capitalize": "^2.0.4",
"cids": "^1.1.5",
"compressorjs": "^1.0.7",
"croppie": "^2.6.5",
"draft-js": "^0.11.7",
"file-type": "^16.5.3",
"generate-avatar": "^1.4.10",
"javascript-time-ago": "^2.3.2",
"js-base64": "^3.5.2",
"js-cookie": "^2.2.1",
"jsbi": "^3.1.4",
"near-api-js": "^0.42.0",
"next": "^12.1.6",
"postcss": "^8.4.12",
"query-string": "^7.0.1",
"react": "^18.1.0",
"react-awesome-animated-number": "^1.0.6",
"react-blurhash": "^0.1.3",
"react-card-flip": "^1.1.5",
"react-content-loader": "^6.0.3",
"react-custom-scrollbars": "^4.2.1",
"react-dom": "^18.1.0",
"react-fast-marquee": "^1.1.3",
"react-google-recaptcha": "^2.1.0",
"react-hamburgers": "^1.0.0",
"react-hook-form": "^6.10.0",
"react-horizontal-scrolling-menu": "^2.7.0",
"react-infinite-scroll-component": "^5.1.0",
"react-intl": "^5.9.2",
"react-linkify": "^1.0.0-alpha",
"react-responsive-carousel": "^3.2.23",
"react-share": "^4.3.1",
"react-slick": "^0.28.1",
"react-tooltip": "^4.2.17",
"recharts": "^2.1.9",
"slick-carousel": "^1.8.1",
"swr": "^1.2.2",
"three": "^0.140.2",
"three-stdlib": "^2.10.1",
"uuid": "^8.3.2",
"zustand": "^3.1.3"
},
"devDependencies": {
"#next/bundle-analyzer": "^12.1.4",
"autoprefixer": "^10.4.4",
"dotenv-cli": "^4.1.1",
"eslint": "^7.30.0",
"eslint-config-next": "^11.0.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^7.0.0",
"lint-staged": "^11.1.2",
"postcss-import": "^13.0.0",
"postcss-preset-env": "^6.7.0",
"prettier": "2.4.1",
"pretty-quick": "^3.1.2",
"tailwindcss": "^3.0.23"
},
"license": "GPL-3.0",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
],
"*.{html,css,less,ejs}": [
"git add"
]
}
}
I am using react-picky package for showing select filter options with typescript you can check the following package.json for versions. Everything working fine when I use create-react-app without typescript.
Maybe some libs got conflicted. I have tried with updating react and react-dom even it shows the same error as the image I have attached.
It is not an import-export issue. I have tried every method to importing exporting.
Package.json
{
"name": "user-portal-client",
"version": "1.0.0",
"description": "Front-end code for the Coinstash user portal.",
"scripts": {
"start": "webpack-dev-server --open",
"start:headless": "webpack-dev-server --host 0.0.0.0 --port 5000 --watch-poll",
"build": "webpack --config webpack.config.prod.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"#types/axios": "^0.14.0",
"#types/classnames": "^2.2.7",
"#types/history": "^4.7.0",
"#types/react": "^16.4.18",
"#types/react-dom": "^16.0.9",
"#types/react-modal": "^3.8.1",
"#types/react-places-autocomplete": "^7.2.3",
"#types/react-router-dom": "^4.3.1",
"#types/react-share": "^2.1.1",
"#types/react-sidebar": "^3.0.0",
"#types/socket.io-client": "^1.4.32",
"#types/styled-components": "4.1.8",
"#types/url-join": "^4.0.0",
"awesome-typescript-loader": "^5.2.1",
"copy-webpack-plugin": "^4.4.2",
"source-map-loader": "^0.2.4",
"styled-components": "^4.2.0",
"ts-node": "^7.0.1",
"typescript": "^3.5.2",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.2.1"
},
"dependencies": {
"#blueprintjs/core": "^3.10.0",
"#blueprintjs/datetime": "^3.6.0",
"#blueprintjs/select": "^3.5.0",
"#types/body-scroll-lock": "^2.6.1",
"#types/reactour": "^1.13.1",
"antd": "^3.16.3",
"apexcharts": "^3.6.8",
"axios": "^0.19.0",
"body-scroll-lock": "^2.6.4",
"classnames": "^2.2.6",
"decimal.js": "^10.1.1",
"mobile-detect": "^1.4.3",
"moment": "^2.22.2",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-google-contacts": "0.0.1",
"react-media": "^1.9.2",
"react-modal": "^3.8.1",
"react-picky": "^4.5.2",
"react-places-autocomplete": "^7.2.0",
"react-router-dom": "^4.3.1",
"react-share": "^3.0.0",
"react-sidebar": "^3.0.2",
"reactour": "^1.15.0",
"recordrtc": "^5.5.2",
"socket.io-client": "^2.2.0",
"url-join": "^4.0.0"
}
}
App.tsx
import * as React from "react";
import * as ReactDOM from "react-dom";
import * as Modal from "react-modal";
import Picky from "react-picky";
declare const document: HTMLDocument;
Modal.setAppElement("#root");
const App = () => (
<div>
<Picky
id="picky"
options={[1, 2, 3, 4, 5]}
value={[]}
multiple={true}
includeSelectAll={true}
includeFilter={true}
onChange={values => console.log(values)}
dropdownHeight={600}
/>
;
</div>
);
ReactDOM.render(<App />, document.getElementById("root"));
declare let module: any;
if (module.hot) {
module.hot.accept();
}
Im trying to create a component using React. I have finished code, but when running "yarn run bundle", the code errors out here and i receive the error code
"Module build failed: SyntaxError: Unexpected token (9:10)"
Below is where I am getting an error. Can anybody think of why?
export class NewBond extends React.Component {
state = {name:''};
Package.json
{
"name": "react-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node --use_strict index.js",
"dev": "nodemon --use_strict index.js",
"bundle": "webpack"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.16.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"jsonwebtoken": "^7.4.1",
"material-ui": "^0.18.1",
"mongoose": "^4.10.4",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"prop-types": "^15.5.10",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1",
"react-tap-event-plugin": "^2.0.1",
"semantic-ui-react": "^0.78.3",
"validator": "^7.0.0",
"yarn": "^1.5.1"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"nodemon": "^1.11.0",
"webpack": "^2.6.1"
}
}
I am trying to extend react-router Router class like this:
class RouterWrapper extends Router {
componentWillMount() {
super.componentWillMount();
}
}
so I have got a typescript compilation error
TS2339: Property 'componentWillMount' does not exist on type 'Component<RouterProps, ComponentState>'. All necessary typings are installed.
At now I have found workaround:
class PatchRouter extends Router {
componentWillMount?();
}
Then extends from PatchRouter, but this solution so ugly.
So, here is my question:
How properly extends Router using typescript 2.2?
my package.json
{
"name": "react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "cross-env NODE_ENV=development node dev-server.js",
},
"author": "",
"license": "ISC",
"dependencies": {
"cross-env": "^3.1.3",
"express": "^4.14.0"
},
"devDependencies": {
"#types/history": "^2.0.45",
"#types/react": "^15.0.0",
"#types/react-dom": "^0.14.19",
"#types/react-router": "^2.0.44",
"core-js": "^2.4.1",
"dom-helpers": "^3.2.0",
"jss": "^6.2.0",
"jss-camel-case": "^3.0.0",
"jss-default-unit": "^5.0.2",
"jss-nested": "^3.0.1",
"jss-vendor-prefixer": "^4.0.0",
"memory-fs": "^0.4.1",
"mobx": "^3.0.1",
"mobx-react": "^4.1.0",
"mobx-react-devtools": "^4.2.11",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-hot-loader": "^3.0.0-beta.6",
"react-router": "^3.0.1",
"ts-loader": "^1.3.0",
"tslib": "^1.5.0",
"typescript": "^2.2.0-dev.20161208",
"url-loader": "^0.5.7",
"webpack": "^2.2.0-rc.6",
"webpack-dev-middleware": "^1.9.0",
"webpack-hot-middleware": "^2.14.0"
}
}
I'm writing tests using Jest & Enzyme in React Native to fully test my components behaviors and inner functions.
Shallow test seems ok but when using mount it just throws
Here's my package.json.
{
"name": "Despirithium",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"buildandroid": "react-native bundle --platform=android --entry-file=index.android.js --bundle-output='android/app/src/main/assets/index.android.bundle?dev=false",
"test": "jest --watch"
},
"dependencies": {
"axios": "^0.15.*",
"dpath": "^2.0.2",
"evosphere-router": "0.1.9",
"immutable": "^3.8.1",
"intl": "^1.2.5",
"lodash": "^4.16.4",
"node-uuid": "^1.4.7",
"normalizr": "^2.2.1",
"react": "15.3.2",
"react-native": "0.36.0",
"react-native-drawer": "^2.3.0",
"react-native-i18n": "^0.1.1",
"react-native-image-picker": "^0.22.12",
"react-native-router-flux": "^3.35.0",
"react-native-tabs": "^1.0.9",
"react-redux": "^4.4.5",
"redux": "^3.6.0",
"redux-immutable": "^3.0.8",
"redux-logger": "^2.7.0",
"redux-thunk": "^2.1.0",
"string-template": "^1.0.0",
"tcomb-form-native": "^0.6.1"
},
"devDependencies": {
"babel-core": "^6.14.0",
"babel-jest": "^17.0.2",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-plugin-transform-react-jsx": "^6.8.0",
"babel-plugin-transform-remove-console": "^6.8.0",
"babel-polyfill": "^6.13.0",
"babel-preset-latest": "6.14.0",
"babel-preset-react-native": "^1.9.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"babel-register": "^6.14.0",
"enzyme": "^2.6.0",
"enzyme-to-json": "^1.3.0",
"faussaire": "^0.2.2",
"faussaire-util": "^0.1.0",
"jest": "^17.0.3",
"jest-enzyme": "^2.0.0",
"jest-react-native": "^17.0.3",
"react-addons-test-utils": "15.3.2",
"react-dom": "15.3.2",
"react-native-fs": "^2.0.1-rc.2",
"react-native-mock": "^0.2.7",
"react-test-renderer": "15.3.2",
"updtr": "^0.2.1"
},
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"setupTestFrameworkScriptFile": "node_modules/jest-enzyme/lib/index.js",
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
"es6"
],
"preset": "jest-react-native"
}
}
For now my test is pretty simple.
global.Promise = require.requireActual('promise');
import 'react-native';
import React from 'react';
import { mount, shallow } from 'enzyme';
import { mountToJson } from 'enzyme-to-json';
import { LoginScene } from '../../../../../../src/bundles/application/ui/scene/public/LoginScene';
import configureStore from '../../../../../../src/configureStore';
import { Provider } from 'react-redux';
import { getState, getInstance } from '../../../../../../src/testing/enzymeUtils';
test('LoginScene', async () => {
const store = await configureStore();
let loginScene;
const wrapper = mount(
<Provider store={store}>
<LoginScene/>
</Provider>
);
expect(mountToJson(wrapper)).toMatchSnapshot();
loginScene = wrapper.find(LoginScene);
getInstance(loginScene)._handleFieldChange('username', 'despirithium');
getInstance(loginScene)._handleFieldChange('password', 'azerty');
expect(getState(wrapper.find(LoginScene)).username).toBe('despirithium');
expect(getState(wrapper.find(LoginScene)).password).toBe('azerty');
});
I would have shallow rendered this but since I need to wrap my scene into the Provider it's not possible.
You may need to wrap Provider in a div. "...Components must return a single root element..." -https://facebook.github.io/react/docs/components-and-props.html