score:0
yes, you can use class components, functional components, and react hooks. but you can't use jsx syntax directly without using this script <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
.
you can use react.createelement()
to create your ui that is natively supported by browsers. for more info, see add react to a website
const e = react.createelement;
function text({ children }) {
react.usememo(() => {
console.log('text renders');
}, [children]);
return e('p', { children });
}
class button extends react.component {
constructor(props) {
super(props);
this.state = { liked: false };
}
render() {
if (this.state.liked) {
return e(text, { children: 'you liked this.' });
}
return e('button', { onclick: () => this.setstate({ liked: true }) }, 'like');
}
}
const domcontainer = document.queryselector('#root');
reactdom.render(e(button), domcontainer);
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>playground</title>
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<style>
</style>
</head>
<body>
<div id="root"></div>
</body>
</html>
score:1
example of using functional components and hooks from cdn version of react.js
// get a hook function
const {usestate} = react;
const example = ({title}) => {
const [count, setcount] = usestate(0);
return (
<div>
<p>{title}</p>
<p>you clicked {count} times</p>
<button onclick={() => setcount(count + 1)}>
click me
</button>
</div>
);
};
// render it
reactdom.render(
<example title="example using hooks:" />,
document.getelementbyid("react")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="react"></div>
Source: stackoverflow.com
Related Query
- When using react cdn links for a site does it require the use of class components or can I use function components?
- CDN links for React packages and how to import it when using react using the scripts from CDN
- "Uncaught ReferenceError: require is not defined" when importing into App.js for React App created using CDN links
- What is the best way to include css files for Prime React components when using Parceljs?
- How to pass state from class components to global state when using react hooks for global state management
- Implement "show more, show less" in React component when using map for adding the components
- React - How to pass props down for the .map function when using functional components
- When we render react Components from an iterable using Array.prototype.map() how is the index generated, and how does react uses it?
- Getting error when I use theme.breakpoints.up in styles for Class Components in React
- When to use ES6 class based React components vs. functional ES6 React components?
- What is the difference between arrow functions and regular functions inside React functional components (no longer using class components)?
- Does the use of es6 named imports reduce the bundle size when using webpack
- How does React re-use child components / keep the state of child components when re-rendering the parent component?
- can i use the tsx extension for test files if using react with typescript
- What is the correct pattern for utility function when using React hooks?
- Webpack does not copy the images that i use into react components
- Is there a non-hook alternative for the React Material-UI makeStyles() function that works for class Components
- Minified React error #310; use the non-minified dev environment for full errors and additional helpful warnings using Chrome through Selenium in React
- ReactJS material-ui use the class `Mui-disabled` for read-only components
- Should the action or store be responsible for transforming data when using React + Flux?
- Why does the render function in react is called twice when using the component strategy?
- when i increment the counter it increases by 2 not one. i am using react context for this
- what is the benefit of using styled components over using css class for the components
- Where does React put the continuous build files when using create-react-app
- How to hide the offcanvas navbar when selecting the links inside of it using react scroll?
- Can I use mock data and proxy api data at the same time in my react project when using node express as a proxy server?
- How to use React for individual site components
- Warning: <Link /> is using incorrect casing. Use PascalCase for React components
- Using Styled Components with nested styles for React Search Bar, trying to place two different SVGs at opposite sides of the search bar
- Approach for different HTML structure with React and using the same components
More Query from same tag
- Graphql Hasura Update if the field is not null
- Axios get request response with 403 error forbidden
- Using Jest+Enzyme+React does not point the right line on error
- In React 17 jquery issue?
- renderToString is making every character of file lowercase, so not able to render, what to do to resolve this?
- How do I update my React context after Axios response
- How to get bootstrap card to stay in the middle of the screen in reactjs
- Attempting to sum values in database array returning 'NaN' error in React frontend
- Set Grid Column width between 2 enums in Semantic UI React
- react-router: How to disable a <Link>, if its active?
- How to display a logo on the AppBar component of react-admin?
- React JS : Yup & Formik Error Message showing multiple times on Submit
- data scope in React using Fetch
- Updating Boolean Value in React State Array
- Component is rendering props.children before parent logic is completed
- Chakra UI : The background does not dim when the drawer opens
- Condtional readOnly checkbox still editable
- Unable to change state when using redirection with history.push
- How to remove jwt token from local storage
- Redux , Getting all the state instead of the state that i passed
- WebSocket connection between reactjs Client and flask-socketio Server doesn't open
- How can I display/edit an ActiveStorage S3 image in React/Javascript using Dropzone?
- Google Auto-ads on React.js application?
- Antd Month DatePicker view is not rendering correcty
- How to change Yup's date format validation
- Login form does not offer password saving on Chrome
- Two independent route systems with react-router
- how to get the text-underline from strapi articles to my gatsby frontend
- Preventing cross site scripting for window.location.href
- How to upload an image to AWS S3 using GraphQL?