score:0
Accepted answer
if you very want to put react class as value into object (without intermediate variable) you can use non es6 syntax instead. the example:
var createreactclass = require('create-react-class');
const myreactclasses = {
firstclass : createreactclass({
render: function() {
return <h1>hello, {this.props.name}</h1>;
},
}
}
the es6 syntax does not return value but create a variable so you need write like this:
class firstclass extends react.component {
myfunction() {
render: function() {
return <h1>hello, {this.props.name}</h1>;
},
},
}
const myreactclasses = {
firstclass : firstclass,
}
# or more simple
const myreactclasses = {
firstclass,
}
score:1
define the class outside of the myreactclasses
constant.
js syntax doesn't allow what you're trying to do. with either method the components should be defined in a file external to the object containing them if for no other reason than readability.
Source: stackoverflow.com
Related Query
- Storing React classes inside a JS variable
- Adding style stored in a variable inside React class
- use of variable inside render function of react component
- How to use an ejs variable inside a react render function?
- Inserting html inside string variable used in React component
- Assignments to the 'timeInterval' variable from inside React Hook useEffect will be lost after each render
- Unable to print javascript variable text in html inside a react component
- How to increment a variable inside .map() in react js
- How to loop inside a react const variable in the render method
- Is it possible to export just a constant variable from inside a React function?
- How to get ThemeContext state as variable in Javascript inside react component?
- When accessing the current state inside a React Hook's setState() call, is the prevState variable a copy or a direct reference to the state object?
- Array only storing last variable when pushing from a JSON in React
- How to pass a variable inside a component in react
- React cannot set variable inside onClick function
- Update React State variable inside an Interval
- is there a way to pass variable inside of a function outside in react
- Storing select option input value in React component inside MongoDB - MERN fail. Stores it as empty string
- Storing current logged in userId in a variable using React SPFx
- Export a variable created inside a then() method within a fetch() function for a React Component
- If I make a variable inside a react component, how do I re-access it on a state change?
- Sorting tailwind classes inside a variable
- React - How to use the current state value as a variable so i can set as a index inside an array
- Use a state variable inside a method in React
- Unable to use div components with bootstrap classes inside map function in react
- Variable is not updated inside a function (using react hooks)
- Storing JS variable before react js loaded
- Access variable from script inside React component
- binding input to variable inside a React Dumb Component with MobX
- NextJs: Calling setInterval with a variable for time inside of a React useEffect Hook
More Query from same tag
- How to Add Arrow to material UI popover Like ToolTip
- Loop through array of items in react
- How to make a Material UI react Button act as a react-router-dom Link?
- browserHistory.push doesn't navigate to new page
- Uncaught undefined error when using React.lazy
- React loading screen before fetching API call
- React Routes are not functioning well over LOGOUT?
- Cannot read property 'width' of undefined (style.width)
- How would one remove all keys on an object which are not present in an Array in JavaScript?
- Problems while starting CRA with npm start
- Update child state based on parent state react functional components
- Mapping through items in static query not showing any results
- Why is my React Authentication component using AWS Amplify being rendered infinitely when using React Router V6 to protect routes
- Trying to reflect changes in Redux State from CurrentUser on React DOM for CurrentUser?
- Unable to render component in react
- Using TypeScript with React HOC, React.lazy and forwarRef
- Our website ad on facebook is not opening in ios 14.7.1
- How to change color of Text Box when validation is incorrect in React JS
- How to return html tags in useEffect?
- Debounce won't execute request max once per second
- Multiple reducers interactions
- need helping displaying table
- React Swipeable tab
- How can I make Dialog take 80% of the screen in Material-UI?
- Textarea overflowing text when typing in repeated characters
- Redux App not working if Redux DevTools Extension is not installed
- Call Method that inside Another Component - React Js
- Prevent fetching when component re-renders
- Docker container exiting immediately after starting when using npm init react-app
- Browserify working with grunt ReacjJS and yii2 vendor path