score:1
const model = (data, predictions, { placeFilter = true, startDateFilter = true, endDateFilter = true }) => {
const getData = () => data.filter(placeFilter).filter(startDateFilter).filter(endDateFilter)
}
You cannot call the above model
function by passing two arguments like model([], [])
as JavaScript will try to destructure the third argument which is undefined
.
You can do this instead:
const model = (data, predictions, { placeFilter = true, startDateFilter = true, endDateFilter = true } = {}) => {
console.log(placeFilter, startDateFilter, endDateFilter)
}
model([], [])
model([], [], { placeFilter: false })
BTW Assuming data
is an array and you're trying to use Array.prototype.filter
, filter
should be called with a callback function that returns a boolean but you're directly passing booleans to all filters.
score:0
const model = (data, predictions, { placeFilter = true, startDateFilter = true, endDateFilter = true } = {}) => {
const getData = () => data.filter(placeFilter).filter(startDateFilter).filter(endDateFilter)
}
score:1
Your parameter could be named to access the default value
const model = (data, predictions, filter = { placeFilter: true, startDateFilter: true, endDateFilter: true }) => {
const getData = () => data.filter(filter.placeFilter).filter(filter.startDateFilter).filter(filter.endDateFilter)
}
Source: stackoverflow.com
Related Query
- cannot read property of undefined using default value
- TypeError when using React: Cannot read property 'firstChild' of undefined
- TypeError: Cannot read property 'match' of undefined when using useParams from react-router
- Cannot read property 'type' of undefined while using react-select with formik
- Cannot read property of undefined when using react hooks
- TypeError: Cannot read property 'width' of undefined when using ImageBackground
- Cannot read property 'conversationId' of undefined while using a reducer function
- Cannot read property 'Header' of undefined when using react-bootstrap modal
- TypeError: Cannot read property 'map' of undefined using ReactJs
- when using {react-select} Cannot read property 'name' of undefined
- TypeError: Cannot read property 'firstName' of undefined - using 'props' in react
- Cannot read property 'handleClick' of undefined when using map
- issue using jest - cannot read property 'yyy' of undefined
- Uncaught TypeError: Cannot read property 'length' of undefined , using react and redux-form validation
- Faced TypeError: Cannot read property 'counter' of undefined when using Redux in React
- Cannot read property 'function' of undefined using this.function (React.js)
- Having trouble using react-moveable with NEXTjs: TypeError: Cannot read property 'userAgent' of undefined
- Cannot read property 'filter' of undefined using ReactJS
- Getting error TypeError: Cannot read property 'id' of undefined using React/Redux action
- Error when trying to map a choropleth using react-leaflet-choropleth: Cannot read property 'map' of undefined
- When Using MUI Button: TypeError: Cannot read property 'borderRadius' of undefined
- Using ref functions with Flow -- property cannot be accessed on possibly undefined value
- vendors.js: Uncaught TypeError: Cannot read property 'apply' of undefined while using webpack
- TypeError: Cannot read property 'setState' of undefined using event
- React - Uncaught TypeError: Cannot read property "name' of undefined using Airtable
- Solved : ReactJS : Uncaught TypeError: Cannot read property 'id' of undefined when posting to a Laravel Controller using axios
- TypeError: Cannot read property 'onMonthSelect' of undefined while using "useRef"
- Cannot read property 'map' of undefined on useState value
- Unhandled Rejection (typeError): Cannot read property of undefined using reactjs axios on google chrome mobile
- Cannot read property 'findDOMNode' of undefined when using stopPropagation - reactJs
More Query from same tag
- My comments for my comment section isn't showing up
- change Url when component renders with react-router-dom?
- Document.getElementsbyid().value issue
- Creating Modal Component with Separate Modal Trigger Button
- Why and how to use classnames utility in React components?
- Passing parameters to current imported class
- How to import and render svg file based on given name from variable in React?
- enable scroll when MUI modal is active React
- Break a text into multiple lines in React
- Updating arrays that are part of a React state
- Does React remove the node with display:none from DOM?
- React Leaflet marker rotation
- How to position the react flatpickr inside a container instead of body
- Bootstrap 4 collapse not working with map in ReactJS
- React JS pass state altering function to child
- webpage is receiving css file but not implementing it
- reactjs onChange not picking up last character
- ComponentwillMount is called twice
- Data is being received but not able to show
- lodash function does not return a single object
- I want to implement select and scroll the window without touching scroll bar using javascript
- MUI - How do you make a horizontal List?
- How can I get pagination work on Meteor 1.5.2 with react?
- Setting up props for a component with an API call to data in MongoDB
- Cypress: How to save CSS color to a variable?
- How to wrap words with anchor tags in react if string contains certain symbols
- React navigation - how to nest drawerNavigator inside stackNavigator
- Setting a unique Key on a Grommet DataTable Reactjs
- React and AppSettings in Azure
- passing data back to calling function of async request