score:7
Accepted answer
you can add a ref
to your span
let spanref = react.createref()
...
<span ref={spanref}>some static text: {somedynamictext}, {someanothertext}</span>
then the text length would simply be spanref.current.textcontent.length
score:8
why not, first, compose the whole string? you can grab its length immediately after, and then render it.
const spanstr = `some static text: ${somedynamictext}, ${someanothertext}`;
const spanlength = spanstr.length;
return(
<somecomp>
...
<span>{spanstr}</span>
...
</somecomp>
)
Source: stackoverflow.com
Related Query
- How to get the length of the text inside the React component
- How to get text element of the given react component in React.cloneElement?
- How to get all the child elements inside a component in unit test using react and enzyme?
- How to get the react component instance corresponding to event.target element in a click handler?
- react - how do I get the size of a component child elements and reposition them
- How to limit the text filed length with input type number in React JS and prevent entry of E,e, -, + etc
- how to get current react component name inside custom react hook?
- how do I interpolate a Link component in Next-i18next / React i18next that changes position in the text
- How to output < inside Text component in React Native?
- How to get text inside Text component onPress in react-native
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How to get the ref of a child component inside parent component in ReactJS
- How do I pass the text data from firestore inside the expandable row and get the document ID to be passed inside the setState?
- how to get a Component variable from another component but their both in the same file React
- How can i get access to the current user inside of react from firebase?
- How to take the input from a react component and pass the length of the input to another react component
- How to get the id of a react material-ui component
- ReactJS: How to get response array inside State(useState) and check the length of the array when rendering/binding
- How to get the text inside a label tag on a click event in ReactJs?
- How to get the value of react component - AceEditor
- How to get the file length for an file in react js
- React Router v6 : How to render multiple component inside and outside a div with the same path
- Can i get the value of my Key inside my react component
- How to link to Routes inside the component rendered by another Route with React Router
- How to get the length of material UI input filed in React JS?
- React SSR : How can my component get the URL search URL parameters in its render method
- How to collapse part of the text inside a card in react bootstrap?
- How to get a component to be fixed at the bottom until the user scrolls to the footer with CSS in React
- How do I filter a list of data by id for my react component to get the name of the object
- How to get the value from button group in react component
More Query from same tag
- How to fix my React Context to render useEffect and reload table data
- Getting ReactTransitionGroup and Redux-Simple-Router to work together
- My posts are not rendered if I return them from the function
- Favicon doesn't show in the browser
- react-router convert const into a class with subroutes
- Can we generate object with jsx fields?
- How to generate path to imported file in React dynamically
- State stored in localStorage gets overwritten on page refresh in React redux? How to persist state?
- How to make a full-sized image scrollable horizontally and vertically just like a map
- How can I show certain elements from an array based on a React State?
- How to get user information from database when the only thing in client browser is the AuthToken?
- Read a File through FileReader Api and Convert it into json object
- Flexbox layout - aligning element at the edge of one another
- How to store firestore collection reference and add as field for different collection in firebase?
- Problem testing material-ui datagrid with react-testing-library
- Rendering Content Conditionally in React JS Based on the state
- typescript props type for styled input component
- React search with pagination without double setState
- Improve my function to reduce duplicated values
- React router native error, Unexpected Token
- How can I prevent metamask from popping up?
- Flow complains about type incompatibility even though I check type first
- Sending Form Data From Frontend to Backend Using Axios Using React
- How to get Material-UI's <TextField/> to return correctly with ref='' like <input/> in ReactJS?
- How to transform a single target file with using React.js JSX transformer?
- Sticky footer for react with react-router-dom
- es6 class method unable to access local state?
- Mocha test "0 passing"
- TypeError: ecwidData.map is not a function
- What's the different between react-router and Next.js