The text displayed using react-pdf appears in various locations on the page

In my project, I am working on incorporating react-pdf to display Hebrew PDF files. I am looking to make specific words clickable with links to other pages, like Wikipedia. To achieve this, I am experimenting with a customTextRenderer function, focusing on the word "על" as an example:

            customTextRenderer={({ str, itemIndex }) => (
                str
                  .split('על')
                  .reduce((strArray, currentValue, currentIndex) => (
                    currentIndex === 0
                      ? ([...strArray, currentValue])
                      : ([...strArray, (
                        // eslint-disable-next-line react/no-array-index-key
                        <a href="/whatever" key={currentIndex}>
                            על
                        </a>
                      ), currentValue])
                  ), []))}

The resulting snippet looks like this:

https://i.stack.imgur.com/teGf7.png

Upon inspection, you may notice that while the first occurrence of the word "על" is aligned correctly, subsequent instances are positioned inconsistently to the left. This irregularity disrupts the flow of the text. Any ideas for how to address this issue would be greatly appreciated.

Answer №1

Here is the solution: implement the direction from right to left specifically on spans.

.react-pdf__Page__textContent span {
    direction: rtl;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Apollo Client's useQuery does not trigger a re-render when new data arrives

I am currently developing a Next.js application. This app pulls data from the server using graphql. The server being used is a postgraphile server. To generate the Apollo-client hooks, I am utilizing graphql-codegen. However, I have come across an issu ...

Managing multiple task cancellations within a redux-saga: How to cancel tasks with the same action type or saga

I am currently exploring how to efficiently cancel multiple tasks of the same action type within redux-saga. During the componentWillUnmount() lifecycle method of my component, I aim to terminate any ongoing tasks that were initiated. Consider the followi ...

Does the Pure Component behave similarly to a regular component when passing an object as a prop?

Is this a correct implementation of a pure Component? interface CheckBoxOptions { multiSelected?: boolean showOuterCheckBoxOnSelected?: boolean } interface Props { checkBoxKey?: any itemTitle?: string isCheckBoxSelected?: boolean checkBoxStyl ...

The component is receiving additional styles that were not specifically imported for it

Currently, I am working on a simple CRUD application in React JS version 18.0.0. One issue that I am facing is related to styling in one of my components, let's call it Home. Strangely, the styles from other components are also being applied to the Ho ...

Consider the presence of various peer dependency versions in a react-typescript library

Currently, I am in the process of converting my react component library react-esri-leaflet to typescript. This library requires the user to install react-leaflet as a peerDependency and offers support for both react-leaflet version 3 (RLV3) and react-leafl ...

The React application is currently hosted in a Docker container and being served by Nginx, but

Currently facing an issue with running a react app on a client's Linux server, both locally and on the server. The server already hosts a site that is served with nginx, and my aim is to integrate the new web app at /new-app. Unfortunately, I have not ...

Should components be stored in state for optimal performance?

Should entire React Components be stored in the component state or redux state? While it is optional (as you can store a string and render the component conditionally), in some cases, it's simpler to just store the whole component. For instance, cons ...

Attempting to incorporate icons into a Material UI table design

Hello, I've incorporated a Material UI table into one of my projects with a design concept similar to this - https://i.stack.imgur.com/i6Fsj.png I'm aiming to include icons within the tables. Here's the code I've worked on so far - ...

Selenium failed to retrieve the text

Code Snippet: List<WebElement> checkboxes=driver.findElements(By.name("ticketLess")); for(WebElement checkbox : checkboxes ){ System.out.println(checkbox.getAttribute("Text")); } HTML Element: <input type="checkbox" name="ticketLess" value= ...

changing a React useState into a Redux reducer based on a separate value

Within my code, I have a simple useState hook that retrieves an id number from an object in an array of objects. This id number is used to display the data of that specific object as shown below: const [itemId, setItemId] = useState<number | undefined&g ...

Is it possible to use Facebook Pixel content IDs as MongoDB ObjectIDs?

My NextJs marketplace has a requirement for Facebook Pixel integration. One of the requirements for any Facebook Pixel event is the use of content_ids, which are usually number values in all examples provided. I am curious if it's possible to substitu ...

Creating a nested object in React's handleChange method: a step-by-step guide

Hey there, I've been working on an onChange function called handleChange for a set of dynamically created inputs. This function receives the event and then performs the following actions: const handleChange = (e) => { const updatedValues = [...va ...

Integrate a fresh global JSX attribute into your React project without the need for @types in node_modules

It is crucial not to mention anything in tsconfig.json. Error Type '{ test: string; }' cannot be assigned to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'. Property 'test' does not exi ...

"Utilizing aws-sdk in a TSX file within a React project: a step-by

When working on a project using TypeScript (tsx) for React, I encountered an issue with uploading images to the server using aws-sdk to communicate with Amazon S3. To resolve this, I made sure to install aws-sdk via npm and typings. UploadFile.tsx import ...

Create boilerplate code easily in VS Code by using its feature that generates code automatically when creating a

Is there a way to set up VS Code so that it automatically creates Typescript/React boilerplate code when I create a new component? import * as React from "react"; export interface props {} export const MyComponent: React.FC<props> = (): J ...

I am experiencing a delay of 5+ seconds when transitioning from the isSubmitting to isSubmitted state in React-hook form. What steps can I take to minimize this delay and enhance

Creating a form with over 30 material-ui components using react-hook form, each requiring unique validation based on field type. Organized folder structure detailed here. detail_page.js serves as the root component initializing useForm with defaultValues ...

Struggling to locate the module in React Native with TypeScript configuration

Currently, I am in the middle of transitioning our react-native project from JavaScript to TypeScript. As I attempt to import old modules, I keep encountering the following error: Cannot find module 'numeral' Oddly enough, the 'numeral&apo ...

The 'browser' field is lacking a proper alias configuration for React, causing an error

Currently enrolled in the React Fundamentals course by Tyler McGinnes, I am making the transition from his coding style to the current accepted standards. Utilizing eslint with the airbnb config and prettier for linting. However, since moving away from Tyl ...

Using react-hook-form for form submission and managing state in React

I want a button that toggles between displaying "Edit" for entering Edit mode and "Save" for submitting the form. However, the issue is that when I press the button while it shows "Edit," it submits the form. Link to codesandbox with the code provided be ...

Explaining the process of defining `this.props` and storing data in the global Redux state

I am currently diving into the world of react and Redux and I'm using a react project on GitHub called overcode/rovercode-ui as a learning tool for understanding react and Redux. As I explore this project, I have come across some intriguing questions. ...