score:0
Accepted answer
you can write it in a better and cleaner way, first of all, you have not to write your module names in pascalcase, getformattedname
will be a better choice! the second thing is that you are using var... avoid that.
the only thing you have to change in the format
function is a format template... and as i see you have only two option (justdate
and datetime
) in this case, so let's write it again:
const getformatteddate = ({ dateobject, includetime }) => {
const dateformat = includetime ? 'mm-dd-yyyy hh:mm:a' : 'mm-dd-yyyy';
return moment.utc(dateobject).format(dateformat);
};
and about the error you got: (but am getting an error that object(...)(...).justdate is not a function
) the problem is that you didn't return justdate
from the formatdate
function.
Source: stackoverflow.com
Related Query
- Creating a reusable date formatter in React
- Creating reusable Button Component with React and Typescript with not assignable type error
- Creating a simple hashtag formatter in React Native
- Ways of creating reusable header with react
- problem creating a reusable filtered table using React
- React JS Creating a reusable component to get API Data
- React prop validation for date objects
- Cannot find namespace 'ctx' error when creating Context with react - typescript
- Creating custom function in React component
- Error while creating new React app ("You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0)")
- React JS get current date
- having multiple instance of same reusable redux react components on the same page/route
- I'm getting error like this while creating react app
- Design Redux actions and reducers for a React reusable component
- Why I got Error while Creating React App?
- Creating a web worker inside React
- TypeScript issues when creating ref for React Native TextInput
- Creating <select> elements in React JS
- How to show time and date in realtime in React JS?
- Why is a .git folder automatically being created when creating a react app?
- Creating 'Div' and 'Span' Components in React Native
- How to restrict date selection in React native ios/android datepicker
- React sorting by date
- npm ERR! 401 Unauthorized: @babel/core@7.1.0 when using creating new react app
- React DatePicker Bootstrap up to date
- Keep getting error while creating react app
- Convert String to Date in React
- Django - DRF (django-rest-framework-social-oauth2) and React creating a user
- Getting error when creating React HOC in Typescript
- Creating a scroll position indicator in React
More Query from same tag
- React i18n break lines in JSON String
- Resize image inside of a container to make it smaller if there is more text
- How do I push items or maybe add an element in array of array
- React application created using create-react-app increments module-scoped variable without reason
- Type 'Element' is missing the following properties from type 'OfferProps': id, firstName, city, price, and 2 more. TS2740
- I can't add elements from function?
- Material UI OutlinedInput and InputLabel overlap
- How to only change selected state value from useDispatch function in redux
- How to create Twilio Flex UI themed hml elements
- Add a number into an array to complete a set of numbers
- Server side rendering with react, react-router, and express
- How to optimize APIs function with the same header
- Have Drop Down read from a list
- how to append formdata of array of objects having image file and title
- How to show a long length string that is taken from a TextField(material-ui)?
- How can I change a color in a material ui sticky header table?
- REACT JS : Uncaught Error: parse Error: Unexpected token
- Actions must be plain objects. Use custom middleware for async actions. react-redux
- How to use existing Angular service in React?
- How does the method menuDataRender() get its input for menuList?
- How to use youtube onPlay={} function with ReactJS?
- Can't find package.json with custom cra-template
- React Router throwing 404 on Azure Linux Web App
- How to get content of a DOM element without being in the React context
- Conditional addEventListener when div ID is at top of window
- Reactjs - Update state of parent after obtaining calculated value from another component function
- useMemo hook not working with map elements
- In Flux architecture, how do you manage client side routing / url states?
- React Webpack proces.env.PUBLIC_URL is undefined
- how to send key[op]:value using axios params in js